History

x86-64: Add support for new psABI relocations

R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX can occur in object files comiled by new binutils. They are not dynamic relocations, so normally wouldn't be a problem for tcc (one doesn't normally mix object files created by different compiler/binutils, static archives are so out :)). If it weren't for the glibc startup code, crt*.o, of course. They now do contain such relocs --> boom. Handle them in the trivial way.

Michael Matz committed 10 years ago

Commit c4d04981 parent d1e15511 file · +10 −4Browse files

Unified · Split

tccelf.c+10−4
@@ -941,6 +941,8 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 940 unmodified lines
941 write64le(ptr, val - rel->r_addend);941 write64le(ptr, val - rel->r_addend);
942 break;942 break;
943 case R_X86_64_GOTPCREL:943 case R_X86_64_GOTPCREL:
944 case 41 /* R_X86_64_GOTPCRELX */:
945 case 42 /* R_X86_64_REX_GOTPCRELX */:
944 write32le(ptr, read32le(ptr) +946 write32le(ptr, read32le(ptr) +
945 (s1->got->sh_addr - addr +947 (s1->got->sh_addr - addr +
946 s1->sym_attrs[sym_index].got_offset - 4));948 s1->sym_attrs[sym_index].got_offset - 4));
@@ -1422,6 +1424,8 @@ ST_FUNC void build_got_entries(TCCState *s1) · 475 unmodified lines
1422 case R_X86_64_GOT32:1424 case R_X86_64_GOT32:
1423 case R_X86_64_GOTTPOFF:1425 case R_X86_64_GOTTPOFF:
1424 case R_X86_64_GOTPCREL:1426 case R_X86_64_GOTPCREL:
1427 case 41 /* R_X86_64_GOTPCRELX */:
1428 case 42 /* R_X86_64_REX_GOTPCRELX */:
1425 case R_X86_64_PLT32:1429 case R_X86_64_PLT32:
1426 sym_index = ELFW(R_SYM)(rel->r_info);1430 sym_index = ELFW(R_SYM)(rel->r_info);
1427 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];1431 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
@@ -1437,13 +1441,13 @@ ST_FUNC void build_got_entries(TCCState *s1) · 9 unmodified lines
1437 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];1441 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
1438 }1442 }
1439 if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL ||1443 if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL ||
1440 type == R_X86_64_PLT32) {1444 type == R_X86_64_PLT32 || type == 41 || type == 42) {
1441 unsigned long ofs;1445 unsigned long ofs;
1442 /* look at the symbol got offset. If none, then add one */1446 /* look at the symbol got offset. If none, then add one */
1443 if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL)1447 if (type == R_X86_64_PLT32)
1448 reloc_type = R_X86_64_JUMP_SLOT;
1449 else
1444 reloc_type = R_X86_64_GLOB_DAT;1450 reloc_type = R_X86_64_GLOB_DAT;
1445 else
1446 reloc_type = R_X86_64_JUMP_SLOT;
1447 ofs = put_got_entry(s1, reloc_type, sym->st_size,1451 ofs = put_got_entry(s1, reloc_type, sym->st_size,
1448 sym->st_info, sym_index);1452 sym->st_info, sym_index);
1449 if (type == R_X86_64_PLT32)1453 if (type == R_X86_64_PLT32)
@@ -1769,6 +1773,8 @@ ST_FUNC void fill_got(TCCState *s1) · 319 unmodified lines
1769 switch (ELFW(R_TYPE) (rel->r_info)) {1773 switch (ELFW(R_TYPE) (rel->r_info)) {
1770 case R_X86_64_GOT32:1774 case R_X86_64_GOT32:
1771 case R_X86_64_GOTPCREL:1775 case R_X86_64_GOTPCREL:
1776 case 41 /* R_X86_64_GOTPCRELX */:
1777 case 42 /* R_X86_64_REX_GOTPCRELX */:
1772 case R_X86_64_PLT32:1778 case R_X86_64_PLT32:
1773 fill_got_entry(s1, rel);1779 fill_got_entry(s1, rel);
1774 break;1780 break;

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