[lld] 167cad5 - [ELF] Improve ADDR tests

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 13:43:19 PDT 2024


Author: Fangrui Song
Date: 2024-05-30T13:43:15-07:00
New Revision: 167cad531db897c708610447d2632f137931c4be

URL: https://github.com/llvm/llvm-project/commit/167cad531db897c708610447d2632f137931c4be
DIFF: https://github.com/llvm/llvm-project/commit/167cad531db897c708610447d2632f137931c4be.diff

LOG: [ELF] Improve ADDR tests

Merge some test files.
The "undefined section" error (`checkIfExists`) was previously untested.

Added: 
    

Modified: 
    lld/test/ELF/linkerscript/addr.test

Removed: 
    lld/test/ELF/linkerscript/expr-invalid-sec.test
    lld/test/ELF/linkerscript/expr-sections.test
    lld/test/ELF/linkerscript/parse-section-in-addr.test


################################################################################
diff  --git a/lld/test/ELF/linkerscript/addr.test b/lld/test/ELF/linkerscript/addr.test
index faec4f91da897..c997525e3dc3f 100644
--- a/lld/test/ELF/linkerscript/addr.test
+++ b/lld/test/ELF/linkerscript/addr.test
@@ -1,20 +1,54 @@
 # REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/addr.s -o %t
-# RUN: ld.lld %t --script %s -o %t1
-# RUN: llvm-objdump --section-headers %t1 | FileCheck %s
-
-# CHECK:      Sections:
-# CHECK-NEXT: Idx Name          Size     VMA              Type
-# CHECK-NEXT:   0               00000000 0000000000000000
-# CHECK-NEXT:   1 .text         00000000 0000000000001000 TEXT
-# CHECK-NEXT:   2 .foo.1        00000008 0000000000001000 DATA
-# CHECK-NEXT:   3 .foo.2        00000008 0000000000001100 DATA
-# CHECK-NEXT:   4 .foo.3        00000008 0000000000001108 DATA
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
+# RUN: ld.lld a.o -T a.lds -o a
+# RUN: llvm-readelf -Ss a | FileCheck %s
 
+# CHECK:      .text      PROGBITS  0000000000001000 001000
+# CHECK-NEXT: .foo-1     PROGBITS  0000000000001001 001001
+# CHECK-NEXT: .foo-2     PROGBITS  0000000000001101 001101
+# CHECK-NEXT: .foo-3     PROGBITS  0000000000001102 001102
+
+# CHECK:      0000000000001001    0 NOTYPE GLOBAL DEFAULT   1 x1
+# CHECK-NEXT: 0000000000001001    0 NOTYPE GLOBAL DEFAULT   1 x2
+# CHECK-NEXT: 0000000000001000    0 NOTYPE GLOBAL DEFAULT   1 x3
+
+## TODO Fix duplicate errors
+# RUN: not ld.lld a.o -T absent.lds 2>&1 | FileCheck %s --check-prefix=ABSENT --implicit-check-not=error:
+# ABSENT-COUNT-2: error: absent.lds:3: undefined section .aaa
+
+## TODO Fix duplicate errors
+# RUN: not ld.lld a.o -T absolute.lds 2>&1 | FileCheck %s --check-prefix=ABSOLUTE --implicit-check-not=error:
+# ABSOLUTE-COUNT-4: error: absolute.lds:2: at least one side of the expression must be absolute
+
+#--- a.s
+.globl _start
+_start: nop
+
+.section .foo-1,"a"; .byte 1
+.section .foo-2,"a"; .byte 2
+.section .foo-3,"a"; .byte 3
+
+#--- a.lds
 SECTIONS {
   . = 0x1000;
-  .text  : { *(.text*) }
-  .foo.1 : { *(.foo.1) }
-  .foo.2 ADDR(.foo.1) + 0x100 : { *(.foo.2) }
-  .foo.3 : { *(.foo.3) }
+  .text  : {
+    *(.text*)
+    x1 = ADDR(.text) + 1; x2 = 1 + ADDR(.text);
+    x3 = ADDR(.text) & 0xffff;
+  }
+  .foo-1 : { *(.foo-1) }
+  .foo-2 ADDR(.foo-1) + 0x100 : { *(.foo-2) }
+  .foo-3 : { *(.foo-3) }
+}
+
+#--- absent.lds
+SECTIONS {
+  . = 0x1000;
+  _aaa = ADDR(.aaa);
+}
+
+#--- absolute.lds
+SECTIONS {
+  foo = ADDR(.text) + ADDR(.text);
 }

diff  --git a/lld/test/ELF/linkerscript/expr-invalid-sec.test b/lld/test/ELF/linkerscript/expr-invalid-sec.test
deleted file mode 100644
index b55006d59e326..0000000000000
--- a/lld/test/ELF/linkerscript/expr-invalid-sec.test
+++ /dev/null
@@ -1,9 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o
-# RUN: not ld.lld -o /dev/null --script %s %t.o -shared 2>&1 | FileCheck %s
-
-# CHECK: error: {{.*}}.test:8: at least one side of the expression must be absolute
-
-SECTIONS {
-  foo = ADDR(.text) + ADDR(.text);
-};

diff  --git a/lld/test/ELF/linkerscript/expr-sections.test b/lld/test/ELF/linkerscript/expr-sections.test
deleted file mode 100644
index cb17e1b77538c..0000000000000
--- a/lld/test/ELF/linkerscript/expr-sections.test
+++ /dev/null
@@ -1,24 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o
-# RUN: ld.lld -o %t.so --script %s %t.o -shared
-# RUN: llvm-readelf -S -s %t.so | FileCheck %s
-
-SECTIONS {
-  . = . + 4;
-  .text : {
-    *(.text)
-    foo1 = ADDR(.text) + 1; bar1 = 1 + ADDR(.text);
-    foo2 = ADDR(.text) & 1; bar2 = 1 & ADDR(.text);
-    foo3 = ADDR(.text) | 1; bar3 = 1 | ADDR(.text);
-  }
-};
-
-# CHECK: [ 5] .text PROGBITS 000000000000014c
-
-# CHECK:    Value         Size Type   Bind   Vis     Ndx Name
-# CHECK: 000000000000014d    0 NOTYPE GLOBAL DEFAULT   5 foo1
-# CHECK: 000000000000014d    0 NOTYPE GLOBAL DEFAULT   5 bar1
-# CHECK: 0000000000000000    0 NOTYPE GLOBAL DEFAULT   5 foo2
-# CHECK: 0000000000000000    0 NOTYPE GLOBAL DEFAULT   5 bar2
-# CHECK: 000000000000014d    0 NOTYPE GLOBAL DEFAULT   5 foo3
-# CHECK: 000000000000014d    0 NOTYPE GLOBAL DEFAULT   5 bar3

diff  --git a/lld/test/ELF/linkerscript/parse-section-in-addr.test b/lld/test/ELF/linkerscript/parse-section-in-addr.test
deleted file mode 100644
index 6f42a6fe2788e..0000000000000
--- a/lld/test/ELF/linkerscript/parse-section-in-addr.test
+++ /dev/null
@@ -1,10 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o
-# RUN: ld.lld -o %t.so --script %s %t.o -shared
-# RUN: llvm-readelf -S %t.so | FileCheck %s
-
-SECTIONS {
- .foo-bar : AT(ADDR(.foo-bar)) { *(.text) }
-}
-
-# CHECK: .foo-bar


        


More information about the llvm-commits mailing list