Hiding symbol names in library

The visibility(“hidden”) attribute does not suppress a symbol from an object file and cannot prevent a symbol being extracted by nm. It just instructs the dynamic linker that the symbol cannot be called from outside a shared library that contains it. Consider a source file file.c containing your example functions: int f_b1(){ return 21 ; … Read more

define a program section in C code (GCC)

The C standard doesn’t say anything about “sections” in the sense that you mean, so you’ll need to use extensions specific to your compiler. With GCC, you will want to use the section attribute: extern void foobar(void) __attribute__((section(“bar”))); There is some limited documentation here, including a warning: Some file formats do not support arbitrary sections … Read more

Fast Division on GCC/ARM

After that, however, it subtracted (dividend/2^31) from the result. Actually, it subtracts dividend >> 31, which is -1 for negative dividend, and 0 for non-negative dividend, when right-shifting negative integers is arithmetic right-shift (and int is 32 bits wide). 0x6666667 = (2^34 + 6)/10 So for x < 0, we have, writing x = 10*k … Read more

linking arbitrary data using GCC ARM toolchain

The following example works for me: $ dd if=/dev/urandom of=binblob bs=1024k count=1 $ objcopy -I binary -O elf32-little binblob binblob.o $ file binblob.o binblob.o: ELF 32-bit LSB relocatable, no machine, version 1 (SYSV), not stripped $ nm -S -t d binblob.o 0000000001048576 D _binary_binblob_end 0000000001048576 A _binary_binblob_size 0000000000000000 D _binary_binblob_start I.e. no need to specify … Read more

GCC preprocessor [duplicate]

Use gcc -E to only run the preprocessor part, e.g. give a file in.c #if 0 0; #endif #if 1 1; #endif running $ gcc -E in.c -o in.i yields a file in.i # 1 “in.cpp” # 1 “<built-in>” # 1 “<command-line>” # 1 “in.cpp” 1; i.e. the parts behind the #if 0 got removed. … Read more

How does the GCC implementation of modulo (%) work, and why does it not use the div instruction?

Second question first: div is a very slow instruction (more than 20 clock cycles). The sequence above consists of more instructions, but they’re all relatively fast, so it’s a net win in terms of speed. The first five instructions (up to and including the shrl) compute i/10 (I’ll explain how in a minute). The next … Read more