[lld] aae025a - [ELF] Improve -r section group tests

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 6 17:10:57 PDT 2024


Author: Fangrui Song
Date: 2024-06-06T17:10:52-07:00
New Revision: aae025a01b423ce43e554bc93da15016fa647beb

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

LOG: [ELF] Improve -r section group tests

Added: 
    

Modified: 
    lld/test/ELF/relocatable-comdat.s

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/relocatable-comdat.s b/lld/test/ELF/relocatable-comdat.s
index 160c48d9fb4d9..45ca9fb7a2484 100644
--- a/lld/test/ELF/relocatable-comdat.s
+++ b/lld/test/ELF/relocatable-comdat.s
@@ -3,46 +3,71 @@
 ## may be rewritten because group members may change their indices. Additionally,
 ## group member may be combined or discarded (e.g. /DISCARD/ or --gc-sections).
 
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: ld.lld -r %t.o %t.o -o %t.ro
-# RUN: llvm-readelf -g -S %t.ro | 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: ld.lld -r a.o a.o -o a.ro
+# RUN: llvm-readelf -g -S a.ro | FileCheck %s
 
-# CHECK: Name    Type  Address          Off    Size   ES Flg Lk        Inf   Al
-# CHECK: .group  GROUP 0000000000000000 {{.*}} 000014 04     {{[1-9]}} [[#]]  4
+# CHECK:      Name           Type     Address          Off    Size   ES Flg Lk    Inf   Al
+# CHECK:      .group         GROUP    0000000000000000 {{.*}} 00001c 04     [[#]] [[#]]  4
+# CHECK-NEXT: .rodata.bar    PROGBITS 0000000000000000 {{.*}} 000001 00  AG  0      0    1
+# CHECK-NEXT: .rodata.foo    PROGBITS 0000000000000000 {{.*}} 000001 00  AG  0      0    1
+# CHECK-NEXT: .text.bar      PROGBITS 0000000000000000 {{.*}} 000008 00 AXG  0      0    1
+# CHECK-NEXT: .rela.text.bar RELA     0000000000000000 {{.*}} 000018 18  IG [[#]] [[#]]  8
+# CHECK-NEXT: .text.foo      PROGBITS 0000000000000000 {{.*}} 000008 00 AXG [[#]] [[#]]  1
+# CHECK-NEXT: .rela.text.foo RELA     0000000000000000 {{.*}} 000018 18  IG [[#]] [[#]]  8
+# CHECK-NEXT: .note.GNU-stack
 
-# CHECK: COMDAT group section [{{.*}}] `.group' [abc] contains 4 sections:
+# CHECK: COMDAT group section [{{.*}}] `.group' [abc] contains 6 sections:
 # CHECK-NEXT: Name
 # CHECK-NEXT: .rodata.bar
 # CHECK-NEXT: .rodata.foo
 # CHECK-NEXT: .text.bar
+# CHECK-NEXT: .rela.text.bar
 # CHECK-NEXT: .text.foo
+# CHECK-NEXT: .rela.text.foo
 
 ## Rewrite SHT_GROUP content if some members are combined.
-# RUN: echo 'SECTIONS { .rodata : {*(.rodata.*)} .text : {*(.text.*)} }' > %t1.lds
-# RUN: ld.lld -r -T %t1.lds %t.o %t.o -o %t1.ro
-# RUN: llvm-readelf -g -S %t1.ro | FileCheck %s --check-prefix=SCRIPT1
+# RUN: echo 'SECTIONS { .rodata : {*(.rodata.*)} .text : {*(.text.*)} }' > combine.lds
+# RUN: ld.lld -r -T combine.lds a.o a.o -o combine.ro
+# RUN: llvm-readelf -g -S combine.ro | FileCheck %s --check-prefix=COMBINE
 
-# SCRIPT1: Name    Type  Address          Off    Size   ES Flg Lk        Inf   Al
-# SCRIPT1: .group  GROUP 0000000000000000 {{.*}} 00000c 04     {{[1-9]}} [[#]]  4
+# COMBINE:      Name           Type     Address          Off    Size   ES Flg Lk    Inf   Al
+# COMBINE:      .rodata        PROGBITS 0000000000000000 {{.*}} 000002 00  AG  0      0    1
+# COMBINE-NEXT: .text          PROGBITS 0000000000000000 {{.*}} 000010 00 AXG  0      0    4
+# COMBINE-NEXT: .group         GROUP    0000000000000000 {{.*}} 000014 04     [[#]] [[#]]  4
+# COMBINE-NEXT: .rela.text     RELA     0000000000000000 {{.*}} 000018 18  IG [[#]] [[#]]  8
+# COMBINE-NEXT: .rela.text     RELA     0000000000000000 {{.*}} 000018 18  IG [[#]] [[#]]  8
+# COMBINE-NEXT: .note.GNU-stack
 
-# SCRIPT1: COMDAT group section [{{.*}}] `.group' [abc] contains 2 sections:
-# SCRIPT1-NEXT: Name
-# SCRIPT1-NEXT: .rodata
-# SCRIPT1-NEXT: .text
+# COMBINE: COMDAT group section [{{.*}}] `.group' [abc] contains 4 sections:
+# COMBINE-NEXT: Name
+# COMBINE-NEXT: .rodata
+# COMBINE-NEXT: .text
+# COMBINE-NEXT: .rela.text
+# COMBINE-NEXT: .rela.text
 
-# RUN: echo 'SECTIONS { /DISCARD/ : {*(.rodata.*)} }' > %t2.lds
-# RUN: ld.lld -r -T %t2.lds %t.o %t.o -o %t2.ro
-# RUN: llvm-readelf -g -S %t2.ro | FileCheck %s --check-prefix=SCRIPT2
+# RUN: echo 'SECTIONS { /DISCARD/ : {*(.rodata.*)} }' > discard-rodata.lds
+# RUN: ld.lld -r -T discard-rodata.lds a.o a.o -o discard-rodata.ro
+# RUN: llvm-readelf -g -S discard-rodata.ro | FileCheck %s --check-prefix=NO-RODATA
 
 ## Handle discarded group members.
-# SCRIPT2: [Nr] Name    Type  Address          Off    Size   ES Flg Lk        Inf   Al
-# SCRIPT2: [ 2] .group  GROUP 0000000000000000 {{.*}} 00000c 04     {{[1-9]}} [[#]]  4
+# NO-RODATA:      Name           Type     Address          Off    Size   ES Flg Lk    Inf   Al
+# NO-RODATA:      .group         GROUP    0000000000000000 {{.*}} 000014 04     [[#]] [[#]]  4
+# NO-RODATA-NEXT: .text.bar      PROGBITS 0000000000000000 {{.*}} 000008 00 AXG  0      0    1
+# NO-RODATA-NEXT: .rela.text.bar RELA     0000000000000000 {{.*}} 000018 18  IG [[#]] [[#]]  8
+# NO-RODATA-NEXT: .text.foo      PROGBITS 0000000000000000 {{.*}} 000008 00 AXG [[#]] [[#]]  1
+# NO-RODATA-NEXT: .rela.text.foo RELA     0000000000000000 {{.*}} 000018 18  IG [[#]] [[#]]  8
+# NO-RODATA-NEXT: .note.GNU-stack
 
-# SCRIPT2: COMDAT group section [{{.*}}] `.group' [abc] contains 2 sections:
-# SCRIPT2-NEXT: Name
-# SCRIPT2-NEXT: .text.bar
-# SCRIPT2-NEXT: .text.foo
+# NO-RODATA:      COMDAT group section [{{.*}}] `.group' [abc] contains 4 sections:
+# NO-RODATA-NEXT: Name
+# NO-RODATA-NEXT: .text.bar
+# NO-RODATA-NEXT: .rela.text.bar
+# NO-RODATA-NEXT: .text.foo
+# NO-RODATA-NEXT: .rela.text.foo
 
+#--- a.s
 .weak abc
 abc:
 
@@ -52,6 +77,6 @@ abc:
 .byte 42
 
 .section .text.bar,"axG", at progbits,abc,comdat
-.quad 42
+.quad abc
 .section .text.foo,"axG", at progbits,abc,comdat
-.long 42
+.quad abc


        


More information about the llvm-commits mailing list