Hi,

On Wed, 9 Jan 2019, Kurt Nalty wrote:

After firing up gdb, and tracing through a few combinations of static and 
dynamically linked object files, I have determined that the segfaults were due 
to usage of procedure linking tables
(.plt) with the statically linked process. The plt addresses are not corrected  
when static loaded, but are corrected during dynamic linking. File 
x86_64-gen.c, lines
630-634 were

#ifdef TCC_TARGET_PE
           greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PC32, 
(int)(vtop->c.i-4));
#else
           greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PLT32, 
(int)(vtop->c.i-4));
#endif

and are replaced by
           greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PC32, 
(int)(vtop->c.i-4));

This restores correct static linking in uClibc-0-9.30 and musl environments. Dynamic linking is unaffected, and continues to use procedure link table jumps and calls.

It's still wrong. The relocation to use really should be PLT32, even though it doesn't often make a difference (*).

I've now found time to look into this, i.e. static linking with uClibc. I fixed some problems in mob and reverted your patch again. A simple hello world now works statically with uClibc. Would be nice if you can retry (and maybe with bigger examples :) ).


Ciao,
Michael.
* it's a historic mistake of the initial x86-64 psABI implementations that PC32 relocs are sometimes used in place of PLT32 relocs (or from a different point of view, that both relocations exist, and not only PC32).

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to