https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80759
--- Comment #53 from Daniel Santos <daniel.santos at pobox dot com> --- (In reply to r...@cebitec.uni-bielefeld.de from comment #52) > Unfortunately, the patch doesn't work, apart from the > > +# define PCREL "@GETPCREL" > > -> @GOTPCREL typo ;-) Ah hah! That would explain why I couldn't use that addressing on gnu/linux, I was looking for the Global Effset Table! :) > At -O0 -g3, it SEGVs at > > Program received signal SIGSEGV, Segmentation fault. > 0x0000000000000000 in ?? () > 1: x/i $pc > => 0x0: <error: Cannot access memory at address 0x0> > (gdb) where > #0 0x0000000000000000 in ?? () > #1 0x0000000100031c58 in do_test_body0 () > at > /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms- > sysv.c:178 > Backtrace stopped: previous frame inner to this frame (corrupt stack?) > > where %rip is 0x0. This happens because most of the addresses are off > by 0x680 bytes. Here's the disassembly: > > (gdb) x/12i 0x0000000100031c58-42 > 0x100031c2e <do_test_body0>: push %rbp > 0x100031c2f <do_test_body0+1>: mov %rsp,%rbp > 0x100031c32 <do_test_body0>: lea 0x1b407(%rip),%rax # > 0x10004d040 > 0x100031c39 <do_test_body0+7>: callq 0x10003247c <regs_to_mem> > 0x100031c3e <do_test_body0+12>: > lea 0x1b4db(%rip),%rax # 0x10004d120 <do_tests_0004_noinfo> > 0x100031c45 <do_test_body0+19>: callq 0x1000324ea <mem_to_regs> > 0x100031c4a <do_test_body0+24>: pop %rax > 0x100031c4b <do_test_body0+25>: > mov %rax,0x1b696(%rip) # 0x10004d2e8 <buffer.5456+104> > 0x100031c52 <do_test_body0+32>: > callq *0x1b688(%rip) # 0x10004d2e0 <buffer.5456+96> > 0x100031c58 <do_test_body0+38>: > mov 0x1bd09(%rip),%rcx # 0x10004d968 <test_data+680> > > Here are the addresses that are supposed to be used: > > %p0 > > (gdb) p/x &test_data.regdata[0] > $11 = 0x10004d6c0 > > %p1 > > (gdb) p/x &test_data.regdata[1] > $12 = 0x10004d7a0 > > %p4 > > (gdb) p/x &test_data.retaddr > $13 = 0x10004d968 > > %p3 > > (gdb) p/x &test_data.fn > $14 = 0x10004d960 > > Only the second use of %p4 is right. > > Rainer Great! When I correct the GOTPCREL typo, I can build this on gnu/linux and I get a variation of the same problem. So apparently GOTPCREL allows you to specify the address of the object, but not an address plus offset -- which is why gcc emits that on Darwin in the first place. All is becoming clear. Also, I lied about needing all registers in do_test_(un)aligned; I forgot that this is called as an ms_abi function. I can clobber rax, r10 and r11 prior to calling the test function and rcx, rdx, and r8-11 after the test function has returned. So I have plenty of registers to accommodate this.