On Fri, Aug 31, 2012 at 3:08 PM, Segher Boessenkool <segher@xxxxxxxxxxxxxxxxxxx> wrote: >> The following example tries to create an elf section with three >> integers using inline assembly. >> asm (".pushsection .test\n" >> ".long 0, %0, %1\n" >> ".popsection" >> :: "i"(ENUM_VAL2), "i"(2)); >> >> But it fails because gcc emits the assembly code with $. >> Is there a way to instruct gcc to avoid emitting $? >> .pushsection .test >> .long 0, $1, $2 <<<<<< >> .popsection > > > asm (".pushsection .test\n" > ".long 0, %P0, %P1\n" > > ".popsection" > :: "i"(ENUM_VAL2), "i"(2)); > > but this is quite hackish, %P isn't meant for this. On newer GCC > versions there is %p, which is better. Thanks - it is what exactly I wanted. $ objdump -s -j .test a.out: file format elf64-x86-64 Contents of section .test: 0000 00000000 01000000 02000000 ............ > > Can't you just do this with attribute((section(".test")))? No. That actual asm block pushes text location along with the constant passed. something like asm ("0:\n" "nop\n" ".pushsection .test\n" ".long 0b, %P0\n" ".popsection" :: "i"(ENUM_VAL2));