From 05f6aa1adef3c5f31c52eb6a38a68df837c1381c Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sun, 13 Jan 2019 06:00:51 +0100 Subject: [PATCH] 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). --- tccelf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tccelf.c b/tccelf.c index 0d372e0f..9f242b85 100644 --- a/tccelf.c +++ b/tccelf.c @@ -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); }