[llvm-branch-commits] [lld] 5d1c723 - [ELF][test] Rewrite st_value=0 copy relocation tests

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Dec 12 16:54:20 PST 2020


Author: Fangrui Song
Date: 2020-12-12T16:50:25-08:00
New Revision: 5d1c723b73aff4a33c4653b9f675cf18dea8c7d6

URL: https://github.com/llvm/llvm-project/commit/5d1c723b73aff4a33c4653b9f675cf18dea8c7d6
DIFF: https://github.com/llvm/llvm-project/commit/5d1c723b73aff4a33c4653b9f675cf18dea8c7d6.diff

LOG: [ELF][test] Rewrite st_value=0 copy relocation tests

The original tests have unneeded symbols and copy-relocation-zero-abs-addr.s
does not actually test anything.

Rewrite them and add copy-relocation-zero-addr.s instead.

Add --soname=b so that the address 0x203400 will be stable.  (When linking an
executable with %t.so, the path %t.so will be recorded in the DT_NEEDED entry if
%t.so doesn't have DT_SONAME. .dynstr will have varying lengths on different
systems.)

Added: 
    lld/test/ELF/copy-relocation-zero-addr.s

Modified: 
    

Removed: 
    lld/test/ELF/Inputs/copy-relocation-zero-abs-addr.s
    lld/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s
    lld/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script
    lld/test/ELF/copy-relocation-zero-abs-addr.s
    lld/test/ELF/copy-relocation-zero-nonabs-addr.s


################################################################################
diff  --git a/lld/test/ELF/Inputs/copy-relocation-zero-abs-addr.s b/lld/test/ELF/Inputs/copy-relocation-zero-abs-addr.s
deleted file mode 100644
index da81e0372d8b..000000000000
--- a/lld/test/ELF/Inputs/copy-relocation-zero-abs-addr.s
+++ /dev/null
@@ -1,7 +0,0 @@
-.globl ver1
-.globl ver2
- ver1 = 0x0
- ver2 = 0x0
-
-.type foo, at object
-.comm foo,16,16

diff  --git a/lld/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s b/lld/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s
deleted file mode 100644
index 26ac7bed195b..000000000000
--- a/lld/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s
+++ /dev/null
@@ -1,7 +0,0 @@
-.balign 1024
-.type foo, at object
-.globl foo
-goo:
-foo:
-  .long 0
-  .size foo,4

diff  --git a/lld/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script b/lld/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script
deleted file mode 100644
index a5807231acd6..000000000000
--- a/lld/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script
+++ /dev/null
@@ -1,3 +0,0 @@
-SECTIONS {
-  goo = 0;
-};

diff  --git a/lld/test/ELF/copy-relocation-zero-abs-addr.s b/lld/test/ELF/copy-relocation-zero-abs-addr.s
deleted file mode 100644
index c0b7abd8eeec..000000000000
--- a/lld/test/ELF/copy-relocation-zero-abs-addr.s
+++ /dev/null
@@ -1,44 +0,0 @@
-// REQUIRES: x86
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/copy-relocation-zero-abs-addr.s -o %t.o
-// RUN: ld.lld -shared -o %t2.so %t.o
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t3.o
-// RUN: ld.lld %t2.so %t3.o -o %t4
-// RUN: llvm-readobj --symbols %t2.so | FileCheck -check-prefix=ABSADDR %s
-// RUN: llvm-readobj -S -r --expand-relocs %t4 | FileCheck %s
-
-// This tests that symbols with absolute addresses are properly
-// handled. Normal DSO symbols are handled as usual.
-
-.text
-.globl _start
-_start:
-  movl $5, foo
-
-// ABSADDR:        Name: ver1
-// ABSADDR-NEXT:   Value: 0x0
-// ABSADDR-NEXT:   Size: 0
-// ABSADDR-NEXT:   Binding: Global
-// ABSADDR-NEXT:   Type: None
-// ABSADDR-NEXT:   Other: 0
-// ABSADDR-NEXT:   Section: Absolute (0xFFF1)
-// ABSADDR-NEXT: }
-// ABSADDR-NEXT: Symbol {
-// ABSADDR-NEXT:   Name: ver2
-// ABSADDR-NEXT:   Value: 0x0
-// ABSADDR-NEXT:   Size: 0
-// ABSADDR-NEXT:   Binding: Global
-// ABSADDR-NEXT:   Type: None
-// ABSADDR-NEXT:   Other: 0
-// ABSADDR-NEXT:   Section: Absolute (0xFFF1)
-// ABSADDR-NEXT: }
-
-// CHECK:      Relocations [
-// CHECK-NEXT:   Section (5) .rela.dyn {
-// CHECK-NEXT:     Relocation {
-// CHECK-NEXT:       Offset:
-// CHECK-NEXT:       Type: R_X86_64_COPY
-// CHECK-NEXT:       Symbol: foo
-// CHECK-NEXT:       Addend:
-// CHECK-NEXT:     }
-// CHECK-NEXT:   }
-// CHECK-NEXT: ]

diff  --git a/lld/test/ELF/copy-relocation-zero-addr.s b/lld/test/ELF/copy-relocation-zero-addr.s
new file mode 100644
index 000000000000..9a1c6c7062ef
--- /dev/null
+++ b/lld/test/ELF/copy-relocation-zero-addr.s
@@ -0,0 +1,44 @@
+# REQUIRES: x86
+# RUN: split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/c.s -o %t/c.o
+# RUN: ld.lld -shared -soname=b -Ttext=0 %t/b.o -o %t/b.so
+
+# RUN: ld.lld %t/a.o %t/b.so -o %t1
+# RUN: llvm-readelf -r -s %t1 | FileCheck %s
+
+## In %t/b.so, foo has st_value==0 and its section alignment is 0x400. The
+## alignment of the copy relocated foo is thus 0x400.
+# CHECK: R_X86_64_COPY {{.*}} foo + 0
+# CHECK: 0000000000203400  4 OBJECT GLOBAL DEFAULT [[#]] foo
+
+## Error if attempting to copy relocate a SHN_ABS symbol (even if st_size is non-zero).
+# RUN: ld.lld -shared -soname=c %t/c.o -o %t/c.so
+# RUN: llvm-readelf -s %t/c.so | FileCheck %s --check-prefix=ABSADDR
+# RUN: not ld.lld %t/a.o %t/c.so -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
+
+# ABSADDR: 0000000000000000  4 OBJECT GLOBAL DEFAULT ABS foo
+# ERR: error: cannot create a copy relocation for symbol foo
+
+#--- a.s
+.text
+.globl _start
+_start:
+  movl $5, foo
+
+#--- b.s
+.data
+.balign 0x400
+.type foo, at object
+.globl foo
+foo:
+  .long 0
+  .size foo, 4
+
+#--- c.s
+.data
+.globl foo
+.type foo, at object
+foo = 0x0
+.size foo, 4

diff  --git a/lld/test/ELF/copy-relocation-zero-nonabs-addr.s b/lld/test/ELF/copy-relocation-zero-nonabs-addr.s
deleted file mode 100644
index 50876056b256..000000000000
--- a/lld/test/ELF/copy-relocation-zero-nonabs-addr.s
+++ /dev/null
@@ -1,29 +0,0 @@
-// REQUIRES: x86
-// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/copy-relocation-zero-nonabs-addr.s -o %t1.o
-// RUN: ld.lld -Ttext=0 -o %t2.so --script=%p/Inputs/copy-relocation-zero-nonabs-addr.script %t1.o -shared
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t3.o
-// RUN: ld.lld %t2.so %t3.o -o %t4
-// RUN: llvm-readobj --symbols %t2.so | FileCheck --check-prefix=CHECKSO %s
-// RUN: llvm-readobj --symbols %t4 | FileCheck %s
-
-.text
-.globl _start
-_start:
-  movl $5, foo
-
-// Make sure foo has st_value == 0.
-// CHECKSO:      Name: foo
-// CHECKSO-NEXT: Value: 0x0
-// CHECKSO-NEXT: Size: 4
-// CHECKSO-NEXT: Binding: Global
-// CHECKSO-NEXT: Type: Object
-// CHECKSO-NEXT: Other: 0
-// CHECKSO-NEXT: Section: .text
-
-// When foo has st_value == 0, it carries the section alignment.
-// In this case, section alignment is 2^10, 0x202400 meets the requirement.
-// CHECK:      Name: foo
-// CHECK-NEXT: Value: 0x202400
-// CHECK-NEXT: Size: 4
-// CHECK-NEXT: Binding: Global
-// CHECK-NEXT: Type: Object


        


More information about the llvm-branch-commits mailing list