[lld] 01e2274 - [ELF] Sort IRELATIVE by offset
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 2 18:47:55 PDT 2024
Author: Fangrui Song
Date: 2024-04-02T18:47:49-07:00
New Revision: 01e227487f4674e2627d3db4f357ee83fa04c7d6
URL: https://github.com/llvm/llvm-project/commit/01e227487f4674e2627d3db4f357ee83fa04c7d6
DIFF: https://github.com/llvm/llvm-project/commit/01e227487f4674e2627d3db4f357ee83fa04c7d6.diff
LOG: [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.
Added:
Modified:
lld/ELF/SyntheticSections.cpp
lld/test/ELF/gnu-ifunc-nonpreemptible.s
Removed:
lld/test/ELF/gnu-ifunc-relative.s
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8708bfeef8fa9a..3494352ee8271c 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1666,7 +1666,7 @@ void RelocationBaseSection::computeRels() {
parallelForEach(relocs,
[symTab](DynamicReloc &rel) { rel.computeRaw(symTab); });
- auto irelative = std::partition(
+ auto irelative = std::stable_partition(
relocs.begin() + numRelativeRelocs, relocs.end(),
[t = target->iRelativeRel](auto &r) { return r.type != t; });
diff --git a/lld/test/ELF/gnu-ifunc-nonpreemptible.s b/lld/test/ELF/gnu-ifunc-nonpreemptible.s
index b209b0cf334688..e03429de230c32 100644
--- a/lld/test/ELF/gnu-ifunc-nonpreemptible.s
+++ b/lld/test/ELF/gnu-ifunc-nonpreemptible.s
@@ -1,62 +1,75 @@
# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
-# RUN: ld.lld %t.o -o %t
-# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck %s --check-prefix=DISASM
-# RUN: llvm-readelf -r -s %t | FileCheck %s
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
+# RUN: ld.lld -shared -soname=b.so b.o -o b.so
-# RUN: ld.lld --export-dynamic %t.o -o %t
-# RUN: llvm-readelf -r -s %t | FileCheck %s
+# RUN: ld.lld a.o -o a
+# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn a | FileCheck %s --check-prefix=DISASM
+# RUN: llvm-readelf -r -s a | FileCheck %s
-# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 2 entries:
+# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 3 entries:
# CHECK-NEXT: Type
-# CHECK-NEXT: R_X86_64_IRELATIVE
-# CHECK-NEXT: R_X86_64_IRELATIVE
+# CHECK-NEXT: {{0*}}[[#%x,O:]] [[#%x,]] R_X86_64_IRELATIVE [[#%x,QUX:]]
+# CHECK-NEXT: {{0*}}[[#O+8]] [[#%x,]] R_X86_64_IRELATIVE
+# CHECK-NEXT: {{0*}}[[#O+16]] [[#%x,]] R_X86_64_IRELATIVE
-# CHECK: 0 NOTYPE LOCAL HIDDEN [[#]] __rela_iplt_start
-# CHECK-NEXT: 0 NOTYPE LOCAL HIDDEN [[#]] __rela_iplt_end
+# CHECK: 0 NOTYPE LOCAL HIDDEN [[#]] __rela_iplt_start
+# CHECK-NEXT: 0 NOTYPE LOCAL HIDDEN [[#]] __rela_iplt_end
+# CHECK-NEXT: {{0*}}[[#QUX]] 0 IFUNC GLOBAL DEFAULT [[#]] qux
-# RUN: ld.lld -pie %t.o -o %t1
-# RUN: llvm-readelf -s %t1 | FileCheck %s --check-prefix=PIC
-# RUN: ld.lld -shared %t.o -o %t2
-# RUN: llvm-readelf -s %t2 | FileCheck %s --check-prefix=PIC
+# RUN: ld.lld -pie a.o b.so -o a1
+# RUN: llvm-readelf -rs a1 | FileCheck %s --check-prefixes=PIC,PIE
+# RUN: ld.lld -shared a.o b.so -o a2
+# RUN: llvm-readelf -rs a2 | FileCheck %s --check-prefix=PIC
+
+# PIC: R_X86_64_GLOB_DAT 0000000000000000 ext + 0
+# PIC-NEXT: {{0*}}[[#%x,O:]] [[#%x,]] R_X86_64_64 0000000000000000 __rela_iplt_start + 0
+# PIC-NEXT: {{0*}}[[#O+8]] [[#%x,]] R_X86_64_64 0000000000000000 __rela_iplt_end + 0
+# PIE-NEXT: {{0*}}[[#O+16]] [[#%x,]] R_X86_64_IRELATIVE
+# PIE-NEXT: {{0*}}[[#O+24]] [[#%x,]] R_X86_64_IRELATIVE
+# PIE-NEXT: {{0*}}[[#O+32]] [[#%x,]] R_X86_64_IRELATIVE
# PIC: 0 NOTYPE WEAK DEFAULT UND __rela_iplt_start
# PIC-NEXT: 0 NOTYPE WEAK DEFAULT UND __rela_iplt_end
# DISASM: Disassembly of section .text:
# DISASM-EMPTY:
-# DISASM-NEXT: <foo>:
+# DISASM-NEXT: <qux>:
+# DISASM: <foo>:
# DISASM: <bar>:
# DISASM: <unused>:
# DISASM: <_start>:
# DISASM-NEXT: callq 0x[[#%x,foo:]]
# DISASM-NEXT: callq 0x[[#%x,bar:]]
+# DISASM-NEXT: callq 0x[[#%x,qux:]]
# DISASM-EMPTY:
# DISASM-NEXT: Disassembly of section .iplt:
# DISASM-EMPTY:
# DISASM-NEXT: <.iplt>:
-# DISASM-NEXT: [[#foo]]: jmpq *{{.*}}(%rip)
+# DISASM-NEXT: [[#qux]]: jmpq *{{.*}}(%rip)
# DISASM-NEXT: pushq $0
# DISASM-NEXT: jmp 0x0
-# DISASM-NEXT: [[#bar]]: jmpq *{{.*}}(%rip)
+# DISASM-NEXT: [[#foo]]: jmpq *{{.*}}(%rip)
# DISASM-NEXT: pushq $1
# DISASM-NEXT: jmp 0x0
+# DISASM-NEXT: [[#bar]]: jmpq *{{.*}}(%rip)
+# DISASM-NEXT: pushq $2
+# DISASM-NEXT: jmp 0x0
-.text
+#--- a.s
+.globl qux, foo, bar
+.type qux, @gnu_indirect_function
.type foo STT_GNU_IFUNC
-.globl foo
-foo:
- ret
-
.type bar STT_GNU_IFUNC
-.globl bar
-bar:
- ret
+qux: ret
+foo: ret
+bar: ret
.type unused, @gnu_indirect_function
.globl unused
-unused:
- ret
+.weak ext
+unused: mov ext at gotpcrel(%rip), %rax
.weak __rela_iplt_start
.weak __rela_iplt_end
@@ -65,7 +78,13 @@ unused:
_start:
call foo
call bar
+ call qux
.data
.quad __rela_iplt_start
.quad __rela_iplt_end
+
+#--- b.s
+.globl ext
+ext:
+ ret
diff --git a/lld/test/ELF/gnu-ifunc-relative.s b/lld/test/ELF/gnu-ifunc-relative.s
deleted file mode 100644
index 278bc5021e6cca..00000000000000
--- a/lld/test/ELF/gnu-ifunc-relative.s
+++ /dev/null
@@ -1,25 +0,0 @@
-// REQUIRES: x86
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-// RUN: ld.lld --strip-all %t.o -o %t
-// RUN: llvm-readobj -r %t | FileCheck %s
-// RUN: ld.lld %t.o -o %t
-// RUN: llvm-readobj -r --symbols %t | FileCheck %s --check-prefixes=CHECK,SYM
-
-.type foo STT_GNU_IFUNC
-.globl foo
-foo:
- ret
-
-.globl _start
-_start:
- call foo
-
-// CHECK: Section ({{.*}}) .rela.dyn {
-// CHECK-NEXT: R_X86_64_IRELATIVE - 0x[[ADDR:.*]]
-// CHECK-NEXT: }
-
-// SYM: Name: foo
-// SYM-NEXT: Value: 0x[[ADDR]]
-// SYM-NEXT: Size: 0
-// SYM-NEXT: Binding: Global
-// SYM-NEXT: Type: GNU_IFunc
More information about the llvm-commits
mailing list