[PATCH] D46764: Fix test cases that check addresses that are not always invariable

Han Shen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 11 11:31:51 PDT 2018


shenhan created this revision.
shenhan added reviewers: ruiu, grimar.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: javed.absar.
Herald added a reviewer: espindola.

https://reviews.llvm.org/D45788  (later reverted) breaks a few test cases, because they check address that are not always invariable (under some condition).

All 4 test case failures are caused by the variable size of .dynstr, which contains absolute path to some .so file. So any section that are placed after .dynstr may have a variable address, check statements asserting those values are flaky.

https://reviews.llvm.org/D45788 makes this more likely to happen, because https://reviews.llvm.org/D45788 rearranges output sections, so .dynstr is usually placed at the beginning of "A" sections.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D46764

Files:
  test/ELF/aarch64-copy.s
  test/ELF/arm-copy.s
  test/ELF/relocation.s
  test/ELF/version-script-extern.s


Index: test/ELF/version-script-extern.s
===================================================================
--- test/ELF/version-script-extern.s
+++ test/ELF/version-script-extern.s
@@ -68,8 +68,11 @@
 # DSO-NEXT:  ]
 # DSO-NEXT:  Version symbols {
 # DSO-NEXT:    Section Name: .gnu.version
-# DSO-NEXT:    Address: 0x300
-# DSO-NEXT:    Offset: 0x300
+// Caution: do not use absolute address below, .gnu.version is placed after
+// .dynstr, which contains absolute path to "version-script-extern.s.tmp.so",
+// so .rodata may start at different address on different systems.
+# DSO-NEXT:    Address: {{.*}}
+# DSO-NEXT:    Offset: {{.*}}
 # DSO-NEXT:    Link: 1
 # DSO-NEXT:    Symbols [
 # DSO-NEXT:      Symbol {
Index: test/ELF/relocation.s
===================================================================
--- test/ELF/relocation.s
+++ test/ELF/relocation.s
@@ -110,20 +110,26 @@
 .section .R_X86_64_64,"a", at progbits
 .global R_X86_64_64
 R_X86_64_64:
- .quad R_X86_64_64
+ .quad 4022250974
 
 // CHECK:      Contents of section .R_X86_64_64:
-// CHECK-NEXT:   200287 87022000 00000000
+// CHECK-NEXT:   {{.*}} deadbeef 00000000
 
 .section .R_X86_64_GOTPCREL,"a", at progbits
 .global R_X86_64_GOTPCREL
 R_X86_64_GOTPCREL:
  .long zed at gotpcrel
-
-// 0x2020F8 - 0x2001D8 = 7952
-// 7952 = 0x101f0000 in little endian
-// CHECK:      Contents of section .R_X86_64_GOTPCREL
-// CHECK-NEXT:   20028f 612e0000
+//     ^^^^^^^^^^^^
+// Note: the above value of .R_X86_64_GOTPCREL is not always a fixed value.
+// The value is calculated by: .got - (.R_X86_64_GOTPCREL+0)
+// When linker arranges sections into below segments:
+//   01     .dynsym .dynstr .R_X86_64_64 .R_X86_64_GOTPCREL ...
+//   02     .text .text2 .R_X86_64_32S .R_X86_64_PC32 .R_X86_64_32S_2 .plt 
+//   03     .got.plt .dynamic .got
+// We see that the size of .dynstr (which contains the absolute path of 
+// "relocation.s.tmp2.so") affects the address of .R_X86_64_GOTPCREL.
+// However, the start addresses of segment 02 and 03 might not be affected,
+// because of huge alignment (usually 0x1000).
 
 .section .R_X86_64_GOT32,"a", at progbits
 .global R_X86_64_GOT32
Index: test/ELF/arm-copy.s
===================================================================
--- test/ELF/arm-copy.s
+++ test/ELF/arm-copy.s
@@ -78,4 +78,8 @@
 
 // RODATA: Contents of section .rodata:
 // S(z) = 0x13004
-// RODATA-NEXT: 10198 04300100
+
+// Caution: do not use absolute address below, .rodata is after .dynstr, which
+// contains absolute path to arm-copy.s.tmp2.so, so .rodata may start
+// at different address on different systems.
+// RODATA-NEXT: {{.*}} 04300100
Index: test/ELF/aarch64-copy.s
===================================================================
--- test/ELF/aarch64-copy.s
+++ test/ELF/aarch64-copy.s
@@ -90,4 +90,8 @@
 
 // RODATA: Contents of section .rodata:
 // S(z) = 0x40014
-// RODATA-NEXT:  10282 14000400
+
+// Caution: do not use absolute address below, .rodata is after .dynstr, which
+// contains absolute path to aarch64-copy.s.tmp2.so, so .rodata may start
+// at different address on different systems.
+// RODATA-NEXT:  {{.*}} 14000400


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46764.146365.patch
Type: text/x-patch
Size: 3134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180511/ca3dd98c/attachment.bin>


More information about the llvm-commits mailing list