Skip to content

Commit 01e2274

Browse files
committed
[ELF] Sort IRELATIVE by offset
Improve the test gnu-ifunc-nonpreemptible.s to check IRELATIVE offsets. Ensure that IRELATIVE offsets are ordered to improve locality.
1 parent c925c16 commit 01e2274

File tree

3 files changed

+48
-54
lines changed

3 files changed

+48
-54
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ void RelocationBaseSection::computeRels() {
16661666
parallelForEach(relocs,
16671667
[symTab](DynamicReloc &rel) { rel.computeRaw(symTab); });
16681668

1669-
auto irelative = std::partition(
1669+
auto irelative = std::stable_partition(
16701670
relocs.begin() + numRelativeRelocs, relocs.end(),
16711671
[t = target->iRelativeRel](auto &r) { return r.type != t; });
16721672

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,75 @@
11
# REQUIRES: x86
2-
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
3-
# RUN: ld.lld %t.o -o %t
4-
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck %s --check-prefix=DISASM
5-
# RUN: llvm-readelf -r -s %t | FileCheck %s
2+
# RUN: rm -rf %t && split-file %s %t && cd %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
5+
# RUN: ld.lld -shared -soname=b.so b.o -o b.so
66

7-
# RUN: ld.lld --export-dynamic %t.o -o %t
8-
# RUN: llvm-readelf -r -s %t | FileCheck %s
7+
# RUN: ld.lld a.o -o a
8+
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn a | FileCheck %s --check-prefix=DISASM
9+
# RUN: llvm-readelf -r -s a | FileCheck %s
910

10-
# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 2 entries:
11+
# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 3 entries:
1112
# CHECK-NEXT: Type
12-
# CHECK-NEXT: R_X86_64_IRELATIVE
13-
# CHECK-NEXT: R_X86_64_IRELATIVE
13+
# CHECK-NEXT: {{0*}}[[#%x,O:]] [[#%x,]] R_X86_64_IRELATIVE [[#%x,QUX:]]
14+
# CHECK-NEXT: {{0*}}[[#O+8]] [[#%x,]] R_X86_64_IRELATIVE
15+
# CHECK-NEXT: {{0*}}[[#O+16]] [[#%x,]] R_X86_64_IRELATIVE
1416

15-
# CHECK: 0 NOTYPE LOCAL HIDDEN [[#]] __rela_iplt_start
16-
# CHECK-NEXT: 0 NOTYPE LOCAL HIDDEN [[#]] __rela_iplt_end
17+
# CHECK: 0 NOTYPE LOCAL HIDDEN [[#]] __rela_iplt_start
18+
# CHECK-NEXT: 0 NOTYPE LOCAL HIDDEN [[#]] __rela_iplt_end
19+
# CHECK-NEXT: {{0*}}[[#QUX]] 0 IFUNC GLOBAL DEFAULT [[#]] qux
1720

18-
# RUN: ld.lld -pie %t.o -o %t1
19-
# RUN: llvm-readelf -s %t1 | FileCheck %s --check-prefix=PIC
20-
# RUN: ld.lld -shared %t.o -o %t2
21-
# RUN: llvm-readelf -s %t2 | FileCheck %s --check-prefix=PIC
21+
# RUN: ld.lld -pie a.o b.so -o a1
22+
# RUN: llvm-readelf -rs a1 | FileCheck %s --check-prefixes=PIC,PIE
23+
# RUN: ld.lld -shared a.o b.so -o a2
24+
# RUN: llvm-readelf -rs a2 | FileCheck %s --check-prefix=PIC
25+
26+
# PIC: R_X86_64_GLOB_DAT 0000000000000000 ext + 0
27+
# PIC-NEXT: {{0*}}[[#%x,O:]] [[#%x,]] R_X86_64_64 0000000000000000 __rela_iplt_start + 0
28+
# PIC-NEXT: {{0*}}[[#O+8]] [[#%x,]] R_X86_64_64 0000000000000000 __rela_iplt_end + 0
29+
# PIE-NEXT: {{0*}}[[#O+16]] [[#%x,]] R_X86_64_IRELATIVE
30+
# PIE-NEXT: {{0*}}[[#O+24]] [[#%x,]] R_X86_64_IRELATIVE
31+
# PIE-NEXT: {{0*}}[[#O+32]] [[#%x,]] R_X86_64_IRELATIVE
2232

2333
# PIC: 0 NOTYPE WEAK DEFAULT UND __rela_iplt_start
2434
# PIC-NEXT: 0 NOTYPE WEAK DEFAULT UND __rela_iplt_end
2535

2636
# DISASM: Disassembly of section .text:
2737
# DISASM-EMPTY:
28-
# DISASM-NEXT: <foo>:
38+
# DISASM-NEXT: <qux>:
39+
# DISASM: <foo>:
2940
# DISASM: <bar>:
3041
# DISASM: <unused>:
3142
# DISASM: <_start>:
3243
# DISASM-NEXT: callq 0x[[#%x,foo:]]
3344
# DISASM-NEXT: callq 0x[[#%x,bar:]]
45+
# DISASM-NEXT: callq 0x[[#%x,qux:]]
3446
# DISASM-EMPTY:
3547
# DISASM-NEXT: Disassembly of section .iplt:
3648
# DISASM-EMPTY:
3749
# DISASM-NEXT: <.iplt>:
38-
# DISASM-NEXT: [[#foo]]: jmpq *{{.*}}(%rip)
50+
# DISASM-NEXT: [[#qux]]: jmpq *{{.*}}(%rip)
3951
# DISASM-NEXT: pushq $0
4052
# DISASM-NEXT: jmp 0x0
41-
# DISASM-NEXT: [[#bar]]: jmpq *{{.*}}(%rip)
53+
# DISASM-NEXT: [[#foo]]: jmpq *{{.*}}(%rip)
4254
# DISASM-NEXT: pushq $1
4355
# DISASM-NEXT: jmp 0x0
56+
# DISASM-NEXT: [[#bar]]: jmpq *{{.*}}(%rip)
57+
# DISASM-NEXT: pushq $2
58+
# DISASM-NEXT: jmp 0x0
4459

45-
.text
60+
#--- a.s
61+
.globl qux, foo, bar
62+
.type qux, @gnu_indirect_function
4663
.type foo STT_GNU_IFUNC
47-
.globl foo
48-
foo:
49-
ret
50-
5164
.type bar STT_GNU_IFUNC
52-
.globl bar
53-
bar:
54-
ret
65+
qux: ret
66+
foo: ret
67+
bar: ret
5568

5669
.type unused, @gnu_indirect_function
5770
.globl unused
58-
unused:
59-
ret
71+
.weak ext
72+
unused: mov ext@gotpcrel(%rip), %rax
6073

6174
.weak __rela_iplt_start
6275
.weak __rela_iplt_end
@@ -65,7 +78,13 @@ unused:
6578
_start:
6679
call foo
6780
call bar
81+
call qux
6882

6983
.data
7084
.quad __rela_iplt_start
7185
.quad __rela_iplt_end
86+
87+
#--- b.s
88+
.globl ext
89+
ext:
90+
ret

lld/test/ELF/gnu-ifunc-relative.s

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)