History

Fix PLT creation for i386

i386 target does not have PC relative loads. Its ABI therefore require ebx register to points to the GOT when executing a PLT entry. This means that PLT entry cannot be used transparently, the compiler needs to expect execution of a PLT entry to be able to use one, that is a PLT entry should only be created if the relocation explicitely asks for it (eg. R_386_PLT32). This patch creates a new target macro PCRELATIVE_DLLPLT to indicate whether a target can do a PC relative load in PLT entry when building a dynamic library. Executable do not normally pose a problem because they are loaded at a fixed address and thus the absolute address of GOT can be used. Note that in such a case, if the compiler does not use a PLT aware relocation for external access then the code relocation will fall on the dynamic loader since there is no PLT entry to relocate too.

Thomas Preud'homme committed 9 years ago

Commit 0bf26281 parent e0fe6906 files · +16 −1Browse files

Unified · Split

6 files
  1. arm-link.c +1 −0
  2. arm64-link.c +1 −0
  3. c67-link.c +1 −0
  4. i386-link.c +1 −0
  5. tccelf.c +11 −1
  6. x86_64-link.c +1 −0
arm-link.c+1−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #define ELF_PAGE_SIZE 0x1000
1616
1717 #define HAVE_SECTION_RELOC
18+#define PCRELATIVE_DLLPLT 1
1819
1920 enum float_abi {
2021 ARM_SOFTFP_FLOAT,
arm64-link.c+1−0
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #define ELF_PAGE_SIZE 0x1000
1515
1616 #define HAVE_SECTION_RELOC
17+#define PCRELATIVE_DLLPLT 1
1718
1819 #else /* !TARGET_DEFS_ONLY */
1920
c67-link.c+1−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #define ELF_PAGE_SIZE 0x1000
1616
1717 #define HAVE_SECTION_RELOC
18+#define PCRELATIVE_DLLPLT 0
1819
1920 #else /* !TARGET_DEFS_ONLY */
2021
i386-link.c+1−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #define ELF_PAGE_SIZE 0x1000
1616
1717 #define HAVE_SECTION_RELOC
18+#define PCRELATIVE_DLLPLT 0
1819
1920 #else /* !TARGET_DEFS_ONLY */
2021
tccelf.c+11−1
@@ -1052,7 +1052,8 @@ ST_FUNC void build_got_entries(TCCState *s1) · 1051 unmodified lines
10521052 /* Proceed with PLT/GOT [entry] creation if any of the following
10531053 condition is met:
10541054 - it is an undefined reference (dynamic relocation needed)
1055− - symbol is absolute (probably created by tcc_add_symbol)
1055+ - symbol is absolute (probably created by tcc_add_symbol and
1056+ thus might be too far from application code)
10561057 - relocation requires a PLT/GOT (BUILD_GOTPLT_ENTRY or
10571058 ALWAYS_GOTPLT_ENTRY). */
10581059 if (sym->st_shndx != SHN_UNDEF &&
@@ -1060,6 +1061,15 @@ ST_FUNC void build_got_entries(TCCState *s1) · 1 unmodified line
10601061 relocs_info[type].gotplt_entry == AUTO_GOTPLT_ENTRY)
10611062 continue;
10621063
1064+ /* Building a dynamic library but target is not capable of PC
1065+ relative PLT entries. It can thus only use PLT entries if
1066+ it expects one to be used (ALWAYS_GOTPLT_ENTRY). */
1067+ if (sym->st_shndx == SHN_UNDEF &&
1068+ s1->output_type == TCC_OUTPUT_DLL &&
1069+ !PCRELATIVE_DLLPLT &&
1070+ relocs_info[type].gotplt_entry == AUTO_GOTPLT_ENTRY)
1071+ continue;
1072+
10631073 #ifdef TCC_TARGET_X86_64
10641074 if (type == R_X86_64_PLT32 &&
10651075 ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT) {
x86_64-link.c+1−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #define ELF_PAGE_SIZE 0x200000
1616
1717 #define HAVE_SECTION_RELOC
18+#define PCRELATIVE_DLLPLT 1
1819
1920 #else /* !TARGET_DEFS_ONLY */
2021

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t