Skip to content

Commit 93c16e7

Browse files
committed
[ELF] Actually sort IRELATIVE by offset
The unstable partition in partitionRels might reverse IRELATIVE relocations, so stable_partition in computeRels would lead to IRELATIVE relocations ordered by decreasing offset. Use stable_partition in partitionRels to get IRELATIVE relocations ordered by increasing offset.
1 parent 2fb5440 commit 93c16e7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,8 @@ void RelocationBaseSection::partitionRels() {
16331633
return;
16341634
const RelType relativeRel = target->relativeRel;
16351635
numRelativeRelocs =
1636-
llvm::partition(relocs, [=](auto &r) { return r.type == relativeRel; }) -
1636+
std::stable_partition(relocs.begin(), relocs.end(),
1637+
[=](auto &r) { return r.type == relativeRel; }) -
16371638
relocs.begin();
16381639
}
16391640

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
# RUN: ld.lld -shared a.o b.so -o a2
2424
# RUN: llvm-readelf -rs a2 | FileCheck %s --check-prefix=PIC
2525

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
26+
# PIC: {{0*}}[[#%x,O:]] [[#%x,]] R_X86_64_RELATIVE
27+
# PIC-NEXT: R_X86_64_GLOB_DAT 0000000000000000 ext + 0
28+
# PIC-NEXT: {{0*}}[[#O-16]] [[#%x,]] R_X86_64_64 0000000000000000 __rela_iplt_start + 0
29+
# PIC-NEXT: {{0*}}[[#O-8]] [[#%x,]] R_X86_64_64 0000000000000000 __rela_iplt_end + 0
30+
# PIE-NEXT: {{0*}}[[#O+8]] [[#%x,]] R_X86_64_IRELATIVE
31+
# PIE-NEXT: {{0*}}[[#O+16]] [[#%x,]] R_X86_64_IRELATIVE
32+
# PIE-NEXT: {{0*}}[[#O+24]] [[#%x,]] R_X86_64_IRELATIVE
3233

3334
# PIC: 0 NOTYPE WEAK DEFAULT UND __rela_iplt_start
3435
# PIC-NEXT: 0 NOTYPE WEAK DEFAULT UND __rela_iplt_end
@@ -83,6 +84,7 @@ _start:
8384
.data
8485
.quad __rela_iplt_start
8586
.quad __rela_iplt_end
87+
.quad .data
8688

8789
#--- b.s
8890
.globl ext

0 commit comments

Comments
 (0)