History

Recognize more relocations as needing GOT/PLT entry

Thomas Preud'homme committed 10 years ago

Commit 6cd23d11 parent cb273fd1 file · +41 −16Browse files

Unified · Split

tccelf.c+41−16
@@ -1034,6 +1034,8 @@ ST_FUNC void build_got_entries(TCCState *s1) · 1033 unmodified lines
1034 type = ELFW(R_TYPE)(rel->r_info);1034 type = ELFW(R_TYPE)(rel->r_info);
1035 switch(type) {1035 switch(type) {
1036#if defined(TCC_TARGET_I386)1036#if defined(TCC_TARGET_I386)
1037 case R_386_PC16:
1038 case R_386_PC32:
1037 case R_386_GOT32:1039 case R_386_GOT32:
1038 case R_386_GOT32X:1040 case R_386_GOT32X:
1039 case R_386_GOTOFF:1041 case R_386_GOTOFF:
@@ -1046,7 +1048,8 @@ ST_FUNC void build_got_entries(TCCState *s1) · 6 unmodified lines
1046 sym_index = ELFW(R_SYM)(rel->r_info);1048 sym_index = ELFW(R_SYM)(rel->r_info);
1047 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];1049 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
1048 /* look at the symbol got offset. If none, then add one */1050 /* look at the symbol got offset. If none, then add one */
1049 if (type == R_386_GOT32 || type == R_386_GOT32X)1051 if (type == R_386_GOT32 || type == R_386_GOT32X ||
1052 type == R_386_16 || type == R_386_32)
1050 reloc_type = R_386_GLOB_DAT;1053 reloc_type = R_386_GLOB_DAT;
1051 else1054 else
1052 reloc_type = R_386_JMP_SLOT;1055 reloc_type = R_386_JMP_SLOT;
@@ -1058,10 +1061,19 @@ ST_FUNC void build_got_entries(TCCState *s1) · 5 unmodified lines
1058 case R_ARM_PC24:1061 case R_ARM_PC24:
1059 case R_ARM_CALL:1062 case R_ARM_CALL:
1060 case R_ARM_JUMP24:1063 case R_ARM_JUMP24:
1061 case R_ARM_GOT32:
1062 case R_ARM_GOTOFF:
1063 case R_ARM_GOTPC:
1064 case R_ARM_PLT32:1064 case R_ARM_PLT32:
1065 case R_ARM_THM_PC22:
1066 case R_ARM_MOVT_ABS:
1067 case R_ARM_MOVW_ABS_NC:
1068 case R_ARM_THM_MOVT_ABS:
1069 case R_ARM_THM_MOVW_ABS_NC:
1070 case R_ARM_PREL31:
1071 case R_ARM_REL32:
1072 case R_ARM_GOTPC:
1073 case R_ARM_GOTOFF:
1074 case R_ARM_GOT32:
1075 case R_ARM_V4BX:
1076
1065 if (!s1->got)1077 if (!s1->got)
1066 build_got(s1);1078 build_got(s1);
1067 sym_index = ELFW(R_SYM)(rel->r_info);1079 sym_index = ELFW(R_SYM)(rel->r_info);
@@ -1071,7 +1083,11 @@ ST_FUNC void build_got_entries(TCCState *s1) · 3 unmodified lines
1071 || s1->output_type == TCC_OUTPUT_MEMORY)) {1083 || s1->output_type == TCC_OUTPUT_MEMORY)) {
1072 unsigned long ofs;1084 unsigned long ofs;
1073 /* look at the symbol got offset. If none, then add one */1085 /* look at the symbol got offset. If none, then add one */
1074 if (type == R_ARM_GOT32)1086 if (type == R_ARM_GOT32 || type == R_ARM_MOVT_ABS ||
1087 type == R_ARM_MOVW_ABS_NC ||
1088 type == R_ARM_THM_MOVT_ABS ||
1089 type == R_ARM_THM_MOVW_ABS_NC || type == R_ARM_ABS32 ||
1090 type == R_ARM_REL32)
1075 reloc_type = R_ARM_GLOB_DAT;1091 reloc_type = R_ARM_GLOB_DAT;
1076 else1092 else
1077 reloc_type = R_ARM_JUMP_SLOT;1093 reloc_type = R_ARM_JUMP_SLOT;
@@ -1082,7 +1098,8 @@ ST_FUNC void build_got_entries(TCCState *s1) · 4 unmodified lines
1082 (char *) symtab_section->link->data + sym->st_name,1098 (char *) symtab_section->link->data + sym->st_name,
1083 type, sym->st_shndx, ofs);1099 type, sym->st_shndx, ofs);
1084#endif1100#endif
1085 if (type != R_ARM_GOT32) {1101 if (type == R_ARM_PC24 || type == R_ARM_CALL ||
1102 type == R_ARM_JUMP24 || type == R_ARM_PLT32) {
1086 addr_t *ptr = (addr_t*)(s1->sections[s->sh_info]->data1103 addr_t *ptr = (addr_t*)(s1->sections[s->sh_info]->data
1087 + rel->r_offset);1104 + rel->r_offset);
1088 /* x must be signed! */1105 /* x must be signed! */
@@ -1177,11 +1194,15 @@ ST_FUNC void build_got_entries(TCCState *s1) · 88 unmodified lines
1177 }1194 }
1178 break;1195 break;
1179#elif defined(TCC_TARGET_X86_64)1196#elif defined(TCC_TARGET_X86_64)
1197 case R_X86_64_32:
1198 case R_X86_64_32S:
1199 case R_X86_64_64:
1200 case R_X86_64_PC32:
1180 case R_X86_64_GOT32:1201 case R_X86_64_GOT32:
1181 case R_X86_64_GOTTPOFF:1202 case R_X86_64_GOTTPOFF:
1182 case R_X86_64_GOTPCREL:1203 case R_X86_64_GOTPCREL:
1183 case R_X86_64_GOTPCRELX:1204 case R_X86_64_GOTPCRELX:
1184 case R_X86_64_REX_GOTPCRELX:1205 case R_X86_64_REX_GOTPCRELX:
1185 case R_X86_64_PLT32:1206 case R_X86_64_PLT32:
1186 sym_index = ELFW(R_SYM)(rel->r_info);1207 sym_index = ELFW(R_SYM)(rel->r_info);
1187 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];1208 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
@@ -1202,16 +1223,20 @@ ST_FUNC void build_got_entries(TCCState *s1) · 14 unmodified lines
1202 type == R_X86_64_PLT32) {1223 type == R_X86_64_PLT32) {
1203 unsigned long ofs;1224 unsigned long ofs;
1204 /* look at the symbol got offset. If none, then add one */1225 /* look at the symbol got offset. If none, then add one */
1205 if (type == R_X86_64_PLT32)1226 if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL ||
1206 reloc_type = R_X86_64_JUMP_SLOT;1227 type == R_X86_64_GOTPCRELX ||
1207 else1228 type == R_X86_64_REX_GOTPCRELX ||
1229 type == R_X86_64_32 || type == R_X86_64_32S ||
1230 type == R_X86_64_64)
1208 reloc_type = R_X86_64_GLOB_DAT;1231 reloc_type = R_X86_64_GLOB_DAT;
1232 else
1233 reloc_type = R_X86_64_JUMP_SLOT;
1209 ofs = put_got_entry(s1, reloc_type, sym->st_size,1234 ofs = put_got_entry(s1, reloc_type, sym->st_size,
1210 sym->st_info, sym_index);1235 sym->st_info, sym_index);
1211 if (type == R_X86_64_PLT32)1236 if (type == R_X86_64_PLT32)
1212 /* We store the place of the generated PLT slot1237 /* We store the place of the generated PLT slot
1213 in our addend. */1238 in our addend. */
1214 rel->r_addend += ofs;1239 rel->r_addend += ofs;
1215 }1240 }
1216 break;1241 break;
1217#else1242#else

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