libc

GLibc optimizations required

大憨熊 提交于 2019-12-10 15:26:31
问题 Why is it not possible recompile GLibc turning off all the optimizations (i.e., -O0)? Particularly in doing this: make CFLAGS='-O0 -w' CXXFLAGS='-O0 -w' I get: #error "glibc cannot be compiled without optimization" 回答1: When I Google the error, the first result tells me exactly why. "In the early startup of the dynamic loader ( _dl_start ), before relocation of the PLT, you cannot make function calls. You must inline the functions you will use during early startup, or call compiler builtins (

getc() as macro and C standard library function definition, coherent?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 13:53:41
问题 In [7.1.4 Use of library functions] , I read : Any function declared in a header may be additionally implemented as a function-like macro defined in the header... and Any invocation of a library function that is implemented as a macro shall expand to code that evaluates each of its arguments exactly once... Then for getc , [7.21.7.5 The getc function] : The getc function is equivalent to fgetc, except that if it is implemented as a macro, it may evaluate stream more than once, so the argument

vectorized strlen getting away with reading unallocated memory

血红的双手。 提交于 2019-12-10 13:16:17
问题 While studying OSX 10.9.4's implementation of strlen, I notice that it always compares a chunk of 16-bytes and skips ahead to the following 16-bytes until it encounters a '\0 '. The relevant part: 3de0: 48 83 c7 10 add $0x10,%rdi 3de4: 66 0f ef c0 pxor %xmm0,%xmm0 3de8: 66 0f 74 07 pcmpeqb (%rdi),%xmm0 3dec: 66 0f d7 f0 pmovmskb %xmm0,%esi 3df0: 85 f6 test %esi,%esi 3df2: 74 ec je 3de0 <__platform_strlen+0x40> 0x10 is 16 bytes in hex. When I saw that, I was wondering: this memory could just

Understanding C errno

怎甘沉沦 提交于 2019-12-10 09:43:58
问题 On my system errno defined as: int * __error(void); #define errno (* __error()) I understand errno is a macro and expands to * __error() function: I searched everywhere (source on my system) but I can't find the definition of the __error() function, can someone show/explain what would/should be the definition of it? How the expression errno = 0 works with the above definition (Assigning 0 to a function?)? Does errno = 0 expands to * __error() = 0 ? Thanks 回答1: The __error function returns a

Why is msvcrt (very very) slow?

最后都变了- 提交于 2019-12-08 04:41:17
问题 I'm specifically asking about the old msvcrt.dll . Hasn't Microsoft updated that library in newer versions of windows? or is that exactly the same library that one can find in Windows 98 distros? I tested msvcrt against Cygwin with a test program that calls malloc a lot of times by a singly linked list blocking queue with mutexes and semaphores. By ifdef s, the program can be compiled to use Posix functions or else use Windows API calls. When compiled by MinGW with WinAPI calls the only

rand() is not returning random values

陌路散爱 提交于 2019-12-08 02:02:04
问题 Its a small code to generate a random hermitian matrix hermitian matrix. I have called srand() before every call to rand(). but still no randomness in the output. I have used c99's complex datatype feature to create a hermitian matrix. I'm not sure where i'm wrong :( #include <stdio.h> #include <math.h> #include <complex.h> #include <stdlib.h> #include <time.h> #define MATSIZE 5 #define RAND_RANGE 100 double complex mat[MATSIZE][MATSIZE]; void gen_mat() { int i =0,j; int real; int img; for(

Debugging postgresql for where 'A' < 'a'

人盡茶涼 提交于 2019-12-07 18:50:14
问题 In a simple comparison test in postgres 9.1 and 8.4 is get the following weird results. postgres=# select 1 one where 'A' < 'a'; one ----- (0 rows) // ..... I would have expected 1 row postgres=# select 1 one where 'A' < 'b'; one ----- 1 (1 row) // ...... this looks OK postgres=# select 1 one where 'A' = 'a'; one ----- (0 rows) // ...... This also looks OK postgres=# select 1 one where 'A' > 'a'; one ----- 1 (1 row) // ...... This is inconsistent with the above results The ascii value of 'A'

intercepting the openat() system call for GNU tar

一曲冷凌霜 提交于 2019-12-07 08:10:45
问题 I'm trying to intercept the openat() system call on Linux using a custom shared library that I can load via LD_PRELOAD . An example intercept-openat.c has this content: #define _GNU_SOURCE #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <dlfcn.h> int (*_original_openat)(int dirfd, const char *pathname, int flags, mode_t mode); void init(void) __attribute__((constructor)); int openat(int dirfd, const char *pathname, int flags, mode_t mode); void

Questions on libc's pointer encryption

十年热恋 提交于 2019-12-07 05:42:25
问题 glibc and eglibc have a PTR_MANGLE , which encrypts pointers in writable memory (more correctly, 'XOR' rather than 'encrypt'). I'm not finding much reading on the feature. man -k PTR_MANGLE returns no hits, and Google is returning some superficial chatter. One of the few definitive articles is Drepper's Pointer Encryption on Live Journal. Is there any in-depth documentation on it? Can it be extended into the user space process, or is it limited to the runtime library? If so, what is the

Moving to different Linux build system, getting error: undefined symbol: stat

别等时光非礼了梦想. 提交于 2019-12-07 04:56:33
问题 This may just be an issue with the build system I am migrating to, but I'll include differences in the two systems and how I encountered the problem. My old build system is a SLES 10 machine. The gcc/cpp/g++ version is 4.1.0 My new system is on SLES 11 SP4, and the gcc/cpp/g++ version is 4.3.4. I am building a shared library; building and linking work fine on the new system. However, at load time on the new system, I get the following: error ./mysharedlib.so: undefined symbol: stat Since the