History

added 64-bit relocation types that required to linking against 64-bit (large model) libraries

Aron BARATH committed 9 years ago

Commit 3a9d6b31 parent 1ed20a01 file · +51 −11Browse files

Unified · Split

x86_64-link.c+51−11
@@ -30,18 +30,23 @@ int code_reloc (int reloc_type) · 29 unmodified lines
3030 case R_X86_64_32:
3131 case R_X86_64_32S:
3232 case R_X86_64_64:
33+ case R_X86_64_GOTPC32:
34+ case R_X86_64_GOTPC64:
3335 case R_X86_64_GOTPCREL:
3436 case R_X86_64_GOTPCRELX:
3537 case R_X86_64_REX_GOTPCRELX:
3638 case R_X86_64_GOTTPOFF:
3739 case R_X86_64_GOT32:
40+ case R_X86_64_GOT64:
3841 case R_X86_64_GLOB_DAT:
3942 case R_X86_64_COPY:
40− case R_X86_64_RELATIVE:
43+ case R_X86_64_RELATIVE:
4144 return 0;
4245
4346 case R_X86_64_PC32:
47+ case R_X86_64_PC64:
4448 case R_X86_64_PLT32:
49+ case R_X86_64_PLTOFF64:
4550 case R_X86_64_JUMP_SLOT:
4651 return 1;
4752 }
@@ -59,7 +64,7 @@ int gotplt_entry_type (int reloc_type) · 11 unmodified lines
5964 case R_X86_64_GLOB_DAT:
6065 case R_X86_64_JUMP_SLOT:
6166 case R_X86_64_COPY:
62− case R_X86_64_RELATIVE:
67+ case R_X86_64_RELATIVE:
6368 return NO_GOTPLT_ENTRY;
6469
6570 /* The following relocs wouldn't normally need GOT or PLT
@@ -69,16 +74,21 @@ int gotplt_entry_type (int reloc_type) · 3 unmodified lines
6974 case R_X86_64_32S:
7075 case R_X86_64_64:
7176 case R_X86_64_PC32:
77+ case R_X86_64_PC64:
7278 return AUTO_GOTPLT_ENTRY;
7379
7480 case R_X86_64_GOTTPOFF:
7581 return BUILD_GOT_ONLY;
7682
7783 case R_X86_64_GOT32:
84+ case R_X86_64_GOT64:
85+ case R_X86_64_GOTPC32:
86+ case R_X86_64_GOTPC64:
7887 case R_X86_64_GOTPCREL:
7988 case R_X86_64_GOTPCRELX:
80− case R_X86_64_REX_GOTPCRELX:
89+ case R_X86_64_REX_GOTPCRELX:
8190 case R_X86_64_PLT32:
91+ case R_X86_64_PLTOFF64:
8292 return ALWAYS_GOTPLT_ENTRY;
8393 }
8494
@@ -171,12 +181,12 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t · 86 unmodified lines
171181 qrel->r_offset = rel->r_offset;
172182 if (esym_index) {
173183 qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64);
174− qrel->r_addend = rel->r_addend;
184+ qrel->r_addend = rel->r_addend;
175185 qrel++;
176186 break;
177187 } else {
178− qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
179− qrel->r_addend = read64le(ptr) + val;
188+ qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
189+ qrel->r_addend = read64le(ptr) + val;
180190 qrel++;
181191 }
182192 }
@@ -211,10 +221,10 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t · 28 unmodified lines
211221 goto plt32pc32;
212222
213223 case R_X86_64_PLT32:
214− /* fallthrough: val already holds the PLT slot address */
224+ /* fallthrough: val already holds the PLT slot address */
215225
216− plt32pc32:
217− {
226+ plt32pc32:
227+ {
218228 long long diff;
219229 diff = (long long)val - addr;
220230 if (diff < -2147483648LL || diff > 2147483647LL) {
@@ -223,17 +233,43 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t · 2 unmodified lines
223233 add32le(ptr, diff);
224234 }
225235 break;
236+
237+ case R_X86_64_PLTOFF64:
238+ add64le(ptr, val - s1->got->sh_addr + rel->r_addend);
239+ break;
240+
241+ case R_X86_64_PC64:
242+ if (s1->output_type == TCC_OUTPUT_DLL) {
243+ /* DLL relocation */
244+ esym_index = s1->sym_attrs[sym_index].dyn_index;
245+ if (esym_index) {
246+ qrel->r_offset = rel->r_offset;
247+ qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC64);
248+ qrel->r_addend = read64le(ptr) + rel->r_addend;
249+ qrel++;
250+ break;
251+ }
252+ }
253+ add64le(ptr, val - addr);
254+ break;
255+
226256 case R_X86_64_GLOB_DAT:
227257 case R_X86_64_JUMP_SLOT:
228258 /* They don't need addend */
229259 write64le(ptr, val - rel->r_addend);
230260 break;
231261 case R_X86_64_GOTPCREL:
232− case R_X86_64_GOTPCRELX:
233− case R_X86_64_REX_GOTPCRELX:
262+ case R_X86_64_GOTPCRELX:
263+ case R_X86_64_REX_GOTPCRELX:
234264 add32le(ptr, s1->got->sh_addr - addr +
235265 s1->sym_attrs[sym_index].got_offset - 4);
236266 break;
267+ case R_X86_64_GOTPC32:
268+ add32le(ptr, s1->got->sh_addr - addr + rel->r_addend);
269+ break;
270+ case R_X86_64_GOTPC64:
271+ add64le(ptr, s1->got->sh_addr - addr + rel->r_addend);
272+ break;
237273 case R_X86_64_GOTTPOFF:
238274 add32le(ptr, val - s1->got->sh_addr);
239275 break;
@@ -241,6 +277,10 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t · 1 unmodified line
241277 /* we load the got offset */
242278 add32le(ptr, s1->sym_attrs[sym_index].got_offset);
243279 break;
280+ case R_X86_64_GOT64:
281+ /* we load the got offset */
282+ add64le(ptr, s1->sym_attrs[sym_index].got_offset);
283+ break;
244284 case R_X86_64_RELATIVE:
245285 /* do nothing */
246286 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