Skip to content

Commit 3d5a60d

Browse files
committed
x86-64: Add R_X86_64_CODE_4_GOTPCRELX
For mov name@GOTPCREL(%rip), %reg test %reg, name@GOTPCREL(%rip) binop name@GOTPCREL(%rip), %reg where binop is one of adc, add, add, cmp, or, sbb, sub, xor instructions, add # define R_X86_64_CODE_4_GOTPCRELX 43 if the instruction starts at 4 bytes before the relocation offset. It similar to R_X86_64_GOTPCRELX. Linker can treat R_X86_64_CODE_4_GOTPCRELX as R_X86_64_GOTPCREL or convert the above instructions to lea name(%rip), %reg mov $name, %reg test $name, %reg binop $name, %reg if the instruction is encoded with the REX2 prefix when possible. bfd/ * elf64-x86-64.c (x86_64_elf_howto_table): Add R_X86_64_CODE_4_GOTPCRELX. (R_X86_64_standard): Updated. (x86_64_reloc_map): Add BFD_RELOC_X86_64_CODE_4_GOTPCRELX. (elf_x86_64_convert_load_reloc): Handle R_X86_64_CODE_4_GOTPCRELX. (elf_x86_64_scan_relocs): Likewise. (elf_x86_64_relocate_section): Likewise. * reloc.c (bfd_reloc_code_real): Add BFD_RELOC_X86_64_CODE_4_GOTPCRELX. * bfd-in2.h: Regenerated. * libbfd.h: Likewise. gas/ * write.h (fix): Add fx_tcbit3. Change fx_unused to 1 bit. * config/tc-i386.c (tc_i386_fix_adjustable): Handle BFD_RELOC_X86_64_CODE_4_GOTPCRELX. (tc_gen_reloc): Likewise. (output_disp): Set fixP->fx_tcbit3 for REX2 prefix. (i386_validate_fix): Generate BFD_RELOC_X86_64_CODE_4_GOTPCRELX if fixp->fx_tcbit3 is set. * config/tc-i386.h (TC_FORCE_RELOCATION_LOCAL): Add BFD_RELOC_X86_64_CODE_4_GOTPCRELX. (TC_FORCE_RELOCATION_ABS): Likewise. * testsuite/gas/i386/x86-64-gotpcrel.s: Add tests for R_X86_64_CODE_4_GOTPCRELX. * testsuite/gas/i386/x86-64-localpic.s: Likewise. * testsuite/gas/i386/x86-64-gotpcrel.d: Updated. * testsuite/gas/i386/x86-64-localpic.d: Likewise. * testsuite/gas/i386/ilp32/x86-64-localpic.d: Likewise. include/ * elf/x86-64.h (elf_x86_64_reloc_type): Add R_X86_64_CODE_4_GOTPCRELX. ld/ * testsuite/ld-x86-64/apx-load1.s: New file. * testsuite/ld-x86-64/apx-load1a.d: Likewise. * testsuite/ld-x86-64/apx-load1b.d: Likewise. * testsuite/ld-x86-64/apx-load1c.d: Likewise. * testsuite/ld-x86-64/apx-load1d.d: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run apx-load1a, apx-load1b, apx-load1c and apx-load1d.
1 parent 5e2f0c9 commit 3d5a60d

File tree

19 files changed

+382
-27
lines changed

19 files changed

+382
-27
lines changed

bfd/bfd-in2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3891,6 +3891,7 @@ enum bfd_reloc_code_real
38913891
BFD_RELOC_X86_64_PLT32_BND,
38923892
BFD_RELOC_X86_64_GOTPCRELX,
38933893
BFD_RELOC_X86_64_REX_GOTPCRELX,
3894+
BFD_RELOC_X86_64_CODE_4_GOTPCRELX,
38943895

38953896
/* ns32k relocations. */
38963897
BFD_RELOC_NS32K_IMM_8,

bfd/elf64-x86-64.c

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,15 @@ static reloc_howto_type x86_64_elf_howto_table[] =
170170
HOWTO(R_X86_64_REX_GOTPCRELX, 0, 4, 32, true, 0, complain_overflow_signed,
171171
bfd_elf_generic_reloc, "R_X86_64_REX_GOTPCRELX", false, 0, 0xffffffff,
172172
true),
173+
HOWTO(R_X86_64_CODE_4_GOTPCRELX, 0, 4, 32, true, 0, complain_overflow_signed,
174+
bfd_elf_generic_reloc, "R_X86_64_CODE_4_GOTPCRELX", false, 0, 0xffffffff,
175+
true),
173176

174177
/* We have a gap in the reloc numbers here.
175178
R_X86_64_standard counts the number up to this point, and
176179
R_X86_64_vt_offset is the value to subtract from a reloc type of
177180
R_X86_64_GNU_VT* to form an index into this table. */
178-
#define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
181+
#define R_X86_64_standard (R_X86_64_CODE_4_GOTPCRELX + 1)
179182
#define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
180183

181184
/* GNU extension to record C++ vtable hierarchy. */
@@ -244,6 +247,7 @@ static const struct elf_reloc_map x86_64_reloc_map[] =
244247
{ BFD_RELOC_X86_64_PLT32_BND, R_X86_64_PLT32_BND, },
245248
{ BFD_RELOC_X86_64_GOTPCRELX, R_X86_64_GOTPCRELX, },
246249
{ BFD_RELOC_X86_64_REX_GOTPCRELX, R_X86_64_REX_GOTPCRELX, },
250+
{ BFD_RELOC_X86_64_CODE_4_GOTPCRELX, R_X86_64_CODE_4_GOTPCRELX, },
247251
{ BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
248252
{ BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
249253
};
@@ -1586,7 +1590,8 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
15861590
bfd_vma roff = irel->r_offset;
15871591
bfd_vma abs_relocation;
15881592

1589-
if (roff < (r_type == R_X86_64_REX_GOTPCRELX ? 3 : 2))
1593+
if (roff < (r_type == R_X86_64_CODE_4_GOTPCRELX
1594+
? 4 : (r_type == R_X86_64_REX_GOTPCRELX ? 3 : 2)))
15901595
return true;
15911596

15921597
raddend = irel->r_addend;
@@ -1597,8 +1602,18 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
15971602
htab = elf_x86_hash_table (link_info, X86_64_ELF_DATA);
15981603
is_pic = bfd_link_pic (link_info);
15991604

1600-
relocx = (r_type == R_X86_64_GOTPCRELX
1601-
|| r_type == R_X86_64_REX_GOTPCRELX);
1605+
if (r_type == R_X86_64_CODE_4_GOTPCRELX)
1606+
{
1607+
/* Skip if this isn't a REX2 instruction. */
1608+
opcode = bfd_get_8 (abfd, contents + roff - 4);
1609+
if (opcode != 0xd5)
1610+
return true;
1611+
1612+
relocx = true;
1613+
}
1614+
else
1615+
relocx = (r_type == R_X86_64_GOTPCRELX
1616+
|| r_type == R_X86_64_REX_GOTPCRELX);
16021617

16031618
/* TRUE if --no-relax is used. */
16041619
no_overflow = link_info->disable_target_specific_optimizations > 1;
@@ -1610,9 +1625,9 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
16101625
/* Convert mov to lea since it has been done for a while. */
16111626
if (opcode != 0x8b)
16121627
{
1613-
/* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1614-
for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1615-
test, xor instructions. */
1628+
/* Only convert R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX
1629+
and R_X86_64_CODE_4_GOTPCRELX for call, jmp or one of adc,
1630+
add, and, cmp, or, sbb, sub, test, xor instructions. */
16161631
if (!relocx)
16171632
return true;
16181633
}
@@ -1797,13 +1812,22 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
17971812
}
17981813
else
17991814
{
1800-
unsigned int rex;
1815+
unsigned int rex = 0;
18011816
unsigned int rex_mask = REX_R;
1817+
unsigned int rex2 = 0;
1818+
unsigned int rex2_mask = REX_R | REX_R << 4;
1819+
bool rex_w = false;
18021820

1803-
if (r_type == R_X86_64_REX_GOTPCRELX)
1804-
rex = bfd_get_8 (abfd, contents + roff - 3);
1805-
else
1806-
rex = 0;
1821+
if (r_type == R_X86_64_CODE_4_GOTPCRELX)
1822+
{
1823+
rex2 = bfd_get_8 (abfd, contents + roff - 3);
1824+
rex_w = (rex2 & REX_W) != 0;
1825+
}
1826+
else if (r_type == R_X86_64_REX_GOTPCRELX)
1827+
{
1828+
rex = bfd_get_8 (abfd, contents + roff - 3);
1829+
rex_w = (rex & REX_W) != 0;
1830+
}
18071831

18081832
if (opcode == 0x8b)
18091833
{
@@ -1824,8 +1848,7 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
18241848
opcode = 0xc7;
18251849
modrm = bfd_get_8 (abfd, contents + roff - 1);
18261850
modrm = 0xc0 | (modrm & 0x38) >> 3;
1827-
if ((rex & REX_W) != 0
1828-
&& ABI_64_P (link_info->output_bfd))
1851+
if (rex_w && ABI_64_P (link_info->output_bfd))
18291852
{
18301853
/* Keep the REX_W bit in REX byte for LP64. */
18311854
r_type = R_X86_64_32S;
@@ -1837,8 +1860,9 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
18371860
use R_X86_64_32 and clear the W bit to avoid
18381861
sign-extend imm32 to imm64. */
18391862
r_type = R_X86_64_32;
1840-
/* Clear the W bit in REX byte. */
1863+
/* Clear the W bit in REX byte and REX2 payload. */
18411864
rex_mask |= REX_W;
1865+
rex2_mask |= REX_W;
18421866
goto rewrite_modrm_rex;
18431867
}
18441868
}
@@ -1867,7 +1891,7 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
18671891

18681892
/* Use R_X86_64_32 with 32-bit operand to avoid relocation
18691893
overflow when sign-extending imm32 to imm64. */
1870-
r_type = (rex & REX_W) != 0 ? R_X86_64_32S : R_X86_64_32;
1894+
r_type = rex_w ? R_X86_64_32S : R_X86_64_32;
18711895

18721896
rewrite_modrm_rex:
18731897
if (abs_relocation)
@@ -1893,6 +1917,13 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
18931917
rex = (rex & ~rex_mask) | (rex & REX_R) >> 2;
18941918
bfd_put_8 (abfd, rex, contents + roff - 3);
18951919
}
1920+
else if (rex2)
1921+
{
1922+
/* Move the R bits to the B bits in REX2 payload byte. */
1923+
rex2 = ((rex2 & ~rex2_mask)
1924+
| (rex2 & (REX_R | REX_R << 4)) >> 2);
1925+
bfd_put_8 (abfd, rex2, contents + roff - 3);
1926+
}
18961927

18971928
/* No addend for R_X86_64_32/R_X86_64_32S relocations. */
18981929
irel->r_addend = 0;
@@ -2058,7 +2089,8 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
20582089
converted_reloc = false;
20592090
if ((r_type == R_X86_64_GOTPCREL
20602091
|| r_type == R_X86_64_GOTPCRELX
2061-
|| r_type == R_X86_64_REX_GOTPCRELX)
2092+
|| r_type == R_X86_64_REX_GOTPCRELX
2093+
|| r_type == R_X86_64_CODE_4_GOTPCRELX)
20622094
&& (h == NULL || h->type != STT_GNU_IFUNC))
20632095
{
20642096
Elf_Internal_Rela *irel = (Elf_Internal_Rela *) rel;
@@ -2108,6 +2140,7 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
21082140
case R_X86_64_GOTPCREL:
21092141
case R_X86_64_GOTPCRELX:
21102142
case R_X86_64_REX_GOTPCRELX:
2143+
case R_X86_64_CODE_4_GOTPCRELX:
21112144
case R_X86_64_TLSGD:
21122145
case R_X86_64_GOT64:
21132146
case R_X86_64_GOTPCREL64:
@@ -2710,6 +2743,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
27102743
case R_X86_64_GOTPCREL:
27112744
case R_X86_64_GOTPCRELX:
27122745
case R_X86_64_REX_GOTPCRELX:
2746+
case R_X86_64_CODE_4_GOTPCRELX:
27132747
case R_X86_64_GOTPCREL64:
27142748
base_got = htab->elf.sgot;
27152749
off = h->got.offset;
@@ -2935,6 +2969,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
29352969
case R_X86_64_GOTPCREL:
29362970
case R_X86_64_GOTPCRELX:
29372971
case R_X86_64_REX_GOTPCRELX:
2972+
case R_X86_64_CODE_4_GOTPCRELX:
29382973
case R_X86_64_GOTPCREL64:
29392974
/* Use global offset table entry as symbol value. */
29402975
case R_X86_64_GOTPLT64:
@@ -3025,7 +3060,8 @@ elf_x86_64_relocate_section (bfd *output_bfd,
30253060
&& !(sym->st_shndx == SHN_ABS
30263061
&& (r_type == R_X86_64_GOTPCREL
30273062
|| r_type == R_X86_64_GOTPCRELX
3028-
|| r_type == R_X86_64_REX_GOTPCRELX)))
3063+
|| r_type == R_X86_64_REX_GOTPCRELX
3064+
|| r_type == R_X86_64_CODE_4_GOTPCRELX)))
30293065
relative_reloc = true;
30303066
}
30313067
}
@@ -3063,6 +3099,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
30633099
if (r_type != R_X86_64_GOTPCREL
30643100
&& r_type != R_X86_64_GOTPCRELX
30653101
&& r_type != R_X86_64_REX_GOTPCRELX
3102+
&& r_type != R_X86_64_CODE_4_GOTPCRELX
30663103
&& r_type != R_X86_64_GOTPCREL64)
30673104
relocation -= htab->elf.sgotplt->output_section->vma
30683105
- htab->elf.sgotplt->output_offset;

bfd/libbfd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
14601460
"BFD_RELOC_X86_64_PLT32_BND",
14611461
"BFD_RELOC_X86_64_GOTPCRELX",
14621462
"BFD_RELOC_X86_64_REX_GOTPCRELX",
1463+
"BFD_RELOC_X86_64_CODE_4_GOTPCRELX",
14631464
"BFD_RELOC_NS32K_IMM_8",
14641465
"BFD_RELOC_NS32K_IMM_16",
14651466
"BFD_RELOC_NS32K_IMM_32",

bfd/reloc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,8 @@ ENUMX
24752475
BFD_RELOC_X86_64_GOTPCRELX
24762476
ENUMX
24772477
BFD_RELOC_X86_64_REX_GOTPCRELX
2478+
ENUMX
2479+
BFD_RELOC_X86_64_CODE_4_GOTPCRELX
24782480
ENUMDOC
24792481
x86-64/elf relocations.
24802482

gas/config/tc-i386.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,6 +3595,7 @@ tc_i386_fix_adjustable (fixS *fixP)
35953595
|| fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCREL
35963596
|| fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX
35973597
|| fixP->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX
3598+
|| fixP->fx_r_type == BFD_RELOC_X86_64_CODE_4_GOTPCRELX
35983599
|| fixP->fx_r_type == BFD_RELOC_X86_64_TLSGD
35993600
|| fixP->fx_r_type == BFD_RELOC_X86_64_TLSLD
36003601
|| fixP->fx_r_type == BFD_RELOC_X86_64_DTPOFF32
@@ -10856,6 +10857,10 @@ output_disp (fragS *insn_start_frag, offsetT insn_start_off)
1085610857
&& !i.prefix[ADDR_PREFIX])
1085710858
fixP->fx_signed = 1;
1085810859

10860+
/* Set fx_tcbit3 for REX2 prefix. */
10861+
if (is_apx_rex2_encoding ())
10862+
fixP->fx_tcbit3 = 1;
10863+
1085910864
/* Check for "call/jmp *mem", "mov mem, %reg",
1086010865
"test %reg, mem" and "binop mem, %reg" where binop
1086110866
is one of adc, add, and, cmp, or, sbb, sub, xor
@@ -15936,9 +15941,14 @@ i386_validate_fix (fixS *fixp)
1593615941
abort ();
1593715942
#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
1593815943
if (fixp->fx_tcbit2)
15939-
fixp->fx_r_type = (fixp->fx_tcbit
15940-
? BFD_RELOC_X86_64_REX_GOTPCRELX
15941-
: BFD_RELOC_X86_64_GOTPCRELX);
15944+
{
15945+
if (fixp->fx_tcbit3)
15946+
fixp->fx_r_type = BFD_RELOC_X86_64_CODE_4_GOTPCRELX;
15947+
else
15948+
fixp->fx_r_type = (fixp->fx_tcbit
15949+
? BFD_RELOC_X86_64_REX_GOTPCRELX
15950+
: BFD_RELOC_X86_64_GOTPCRELX);
15951+
}
1594215952
else
1594315953
#endif
1594415954
fixp->fx_r_type = BFD_RELOC_X86_64_GOTPCREL;
@@ -16042,6 +16052,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
1604216052
case BFD_RELOC_X86_64_GOTPCREL:
1604316053
case BFD_RELOC_X86_64_GOTPCRELX:
1604416054
case BFD_RELOC_X86_64_REX_GOTPCRELX:
16055+
case BFD_RELOC_X86_64_CODE_4_GOTPCRELX:
1604516056
case BFD_RELOC_386_PLT32:
1604616057
case BFD_RELOC_386_GOT32:
1604716058
case BFD_RELOC_386_GOT32X:
@@ -16200,6 +16211,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
1620016211
case BFD_RELOC_X86_64_GOTPCREL:
1620116212
case BFD_RELOC_X86_64_GOTPCRELX:
1620216213
case BFD_RELOC_X86_64_REX_GOTPCRELX:
16214+
case BFD_RELOC_X86_64_CODE_4_GOTPCRELX:
1620316215
case BFD_RELOC_X86_64_TLSGD:
1620416216
case BFD_RELOC_X86_64_TLSLD:
1620516217
case BFD_RELOC_X86_64_GOTTPOFF:

gas/config/tc-i386.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,17 @@ extern int tc_i386_fix_adjustable (struct fix *);
171171
|| (FIX)->fx_r_type == BFD_RELOC_386_GOTPC \
172172
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCREL \
173173
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX \
174-
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX)
174+
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX \
175+
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_CODE_4_GOTPCRELX)
175176

176177
#define TC_FORCE_RELOCATION_ABS(FIX) \
177178
(TC_FORCE_RELOCATION (FIX) \
178179
|| (FIX)->fx_r_type == BFD_RELOC_386_GOT32 \
179180
|| (FIX)->fx_r_type == BFD_RELOC_386_GOT32X \
180181
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCREL \
181182
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX \
182-
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX)
183+
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX \
184+
|| (FIX)->fx_r_type == BFD_RELOC_X86_64_CODE_4_GOTPCRELX)
183185

184186
extern int i386_parse_name (char *, expressionS *, char *);
185187
#define md_parse_name(s, e, m, c) i386_parse_name (s, e, c)

gas/testsuite/gas/i386/ilp32/x86-64-localpic.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
#readelf: -rsW
44
#name: x86-64 (ILP32) local PIC
55

6-
Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 2 entries:
6+
Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 4 entries:
77
+Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend
88
[0-9a-f]+ +[0-9a-f]+ R_X86_64_REX_GOTPCRELX +[0-9a-f]+ +foo - 4
99
[0-9a-f]+ +[0-9a-f]+ R_X86_64_REX_GOTPCRELX +[0-9a-f]+ +bar - 4
10+
[0-9a-f]+ +[0-9a-f]+ R_X86_64_CODE_4_GOTPCRELX +[0-9a-f]+ +foo - 4
11+
[0-9a-f]+ +[0-9a-f]+ R_X86_64_CODE_4_GOTPCRELX +[0-9a-f]+ +bar - 4
1012
#...
1113
+[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +NOTYPE +LOCAL +DEFAULT +[0-9]+ +foo
1214
+[0-9]+: +fffffff0 +[0-9a-f]+ +NOTYPE +LOCAL +DEFAULT +ABS +bar

gas/testsuite/gas/i386/x86-64-gotpcrel.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,16 @@ Disassembly of section .text:
2424
[ ]*[a-f0-9]+: ff 90 00 00 00 00 call \*0x0\(%rax\) 5a: R_X86_64_GOTPCREL foo
2525
[ ]*[a-f0-9]+: ff 25 00 00 00 00 jmp \*0x0\(%rip\) # 64 <_start\+0x64> 60: R_X86_64_GOTPCRELX foo-0x4
2626
[ ]*[a-f0-9]+: ff a1 00 00 00 00 jmp \*0x0\(%rcx\) 66: R_X86_64_GOTPCREL foo
27+
[ ]*[a-f0-9]+: d5 18 c7 c0 00 00 00 00 mov \$0x0,%r16 6e: R_X86_64_GOTPCREL foo
28+
[ ]*[a-f0-9]+: d5 48 8b 24 25 00 00 00 00 mov 0x0,%r20 77: R_X86_64_GOTPCREL foo
29+
[ ]*[a-f0-9]+: d5 48 8b 35 00 00 00 00 mov 0x0\(%rip\),%r22 # 83 <_start\+0x83> 7f: R_X86_64_CODE_4_GOTPCRELX foo-0x4
30+
[ ]*[a-f0-9]+: d5 59 8b b4 24 00 00 00 00 mov 0x0\(%r28\),%r22 88: R_X86_64_GOTPCREL foo
31+
[ ]*[a-f0-9]+: d5 10 ff 90 00 00 00 00 call \*0x0\(%r16\) 90: R_X86_64_GOTPCREL foo
32+
[ ]*[a-f0-9]+: d5 11 ff a4 24 00 00 00 00 jmp \*0x0\(%r28\) 99: R_X86_64_GOTPCREL foo
33+
[ ]*[a-f0-9]+: d5 18 c7 c0 00 00 00 00 mov \$0x0,%r16 a1: R_X86_64_GOTPCREL foo
34+
[ ]*[a-f0-9]+: d5 48 8b 24 25 00 00 00 00 mov 0x0,%r20 aa: R_X86_64_GOTPCREL foo
35+
[ ]*[a-f0-9]+: d5 48 8b 35 00 00 00 00 mov 0x0\(%rip\),%r22 # b6 <_start\+0xb6> b2: R_X86_64_CODE_4_GOTPCRELX foo-0x4
36+
[ ]*[a-f0-9]+: d5 59 8b b4 24 00 00 00 00 mov 0x0\(%r28\),%r22 bb: R_X86_64_GOTPCREL foo
37+
[ ]*[a-f0-9]+: d5 10 ff 90 00 00 00 00 call \*0x0\(%r16\) c3: R_X86_64_GOTPCREL foo
38+
[ ]*[a-f0-9]+: d5 11 ff a4 24 00 00 00 00 jmp \*0x0\(%r28\) cc: R_X86_64_GOTPCREL foo
2739
#pass

gas/testsuite/gas/i386/x86-64-gotpcrel.s

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,22 @@ _start:
2121
call QWORD PTR [rax + foo@GOTPCREL]
2222
jmp QWORD PTR [rip + foo@GOTPCREL]
2323
jmp QWORD PTR [rcx + foo@GOTPCREL]
24+
25+
.att_syntax prefix
26+
movq $foo@GOTPCREL, %r16
27+
movq foo@GOTPCREL, %r20
28+
movq foo@GOTPCREL(%rip), %r22
29+
movq foo@GOTPCREL(%r28), %r22
30+
31+
call *foo@GOTPCREL(%r16)
32+
jmp *foo@GOTPCREL(%r28)
33+
34+
.intel_syntax noprefix
35+
36+
mov r16, offset foo@gotpcrel
37+
mov r20, QWORD PTR [foo@GOTPCREL]
38+
mov r22, QWORD PTR [rip + foo@GOTPCREL]
39+
mov r22, QWORD PTR [r28 + foo@GOTPCREL]
40+
41+
call QWORD PTR [r16 + foo@GOTPCREL]
42+
jmp QWORD PTR [r28 + foo@GOTPCREL]

gas/testsuite/gas/i386/x86-64-localpic.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
#readelf: -rsW
33
#name: x86-64 local PIC
44

5-
Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 2 entries:
5+
Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 4 entries:
66
+Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
77
[0-9a-f]+ +[0-9a-f]+ R_X86_64_REX_GOTPCRELX +[0-9a-f]+ +foo - 4
88
[0-9a-f]+ +[0-9a-f]+ R_X86_64_REX_GOTPCRELX +[0-9a-f]+ +bar - 4
9+
[0-9a-f]+ +[0-9a-f]+ R_X86_64_CODE_4_GOTPCRELX +[0-9a-f]+ +foo - 4
10+
[0-9a-f]+ +[0-9a-f]+ R_X86_64_CODE_4_GOTPCRELX +[0-9a-f]+ +bar - 4
911
#...
1012
+[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +NOTYPE +LOCAL +DEFAULT +[0-9]+ +foo
1113
+[0-9]+: +0+fffffff0 +[0-9a-f]+ +NOTYPE +LOCAL +DEFAULT +ABS +bar

0 commit comments

Comments
 (0)