Fix -static linking with uClibc

symbols are local when defined and referred to from the executable.
Also, we need to relocate the .got section when this is a static link
(our static linking effectively generates code as if this were a dynamic
link with PLT and GOT, and then emulates the runtime loader).
This commit is contained in:
Michael Matz 2019-01-13 06:00:51 +01:00
parent adbe794a46
commit 05f6aa1ade

View File

@ -1084,8 +1084,10 @@ ST_FUNC void build_got_entries(TCCState *s1)
#ifdef TCC_TARGET_X86_64
if ((type == R_X86_64_PLT32 || type == R_X86_64_PC32) &&
sym->st_shndx != SHN_UNDEF &&
(ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT ||
ELFW(ST_BIND)(sym->st_info) == STB_LOCAL)) {
ELFW(ST_BIND)(sym->st_info) == STB_LOCAL ||
s1->output_type == TCC_OUTPUT_EXE)) {
rel->r_info = ELFW(R_INFO)(sym_index, R_X86_64_PC32);
continue;
}
@ -1841,7 +1843,7 @@ static int final_sections_reloc(TCCState *s1)
/* XXX: ignore sections with allocated relocations ? */
for(i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i];
if (s->reloc && s != s1->got)
if (s->reloc && (s != s1->got || s1->static_link))
relocate_section(s1, s);
}