[lld] 51475e4 - [ELF][test] Add linkerscript/linkorder-linked-to.s

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 15:17:37 PDT 2020


Author: Fangrui Song
Date: 2020-03-30T15:17:29-07:00
New Revision: 51475e4023650c007b77a84cc8606923baa944dc

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

LOG: [ELF][test] Add linkerscript/linkorder-linked-to.s

Delete relocatable-linkorder.s which is covered.

Added: 
    lld/test/ELF/linkerscript/linkorder-linked-to.s

Modified: 
    

Removed: 
    lld/test/ELF/relocatable-linkorder.s


################################################################################
diff  --git a/lld/test/ELF/linkerscript/linkorder-linked-to.s b/lld/test/ELF/linkerscript/linkorder-linked-to.s
new file mode 100644
index 000000000000..c203744bbde4
--- /dev/null
+++ b/lld/test/ELF/linkerscript/linkorder-linked-to.s
@@ -0,0 +1,74 @@
+# REQUIRES: x86
+## Test how we set the sh_link field of a SHF_LINK_ORDER output section.
+## Additionally, test that in a relocatable link, SHF_LINK_ORDER sections are
+## not combined. Combining them will arbitrarily choose a single output
+## section, losing tracking of correct dependencies.
+
+# RUN: llvm-mc -filetype=obj --triple=x86_64 %s -o %t.o
+
+## In the absence of a SECTIONS command.
+# RUN: ld.lld %t.o -o %t
+# RUN: llvm-readelf -S -x foo %t | FileCheck --check-prefixes=EXE,EXE-HEX %s
+# RUN: ld.lld %t.o -o %t.ro -r
+# RUN: llvm-readelf -S %t.ro | FileCheck --check-prefix=REL %s
+
+## A non-relocatable link places readonly sections before read-executable sections.
+# EXE:      [Nr] Name     {{.*}} Flg Lk
+# EXE-NEXT: [ 0]
+# EXE-NEXT: [ 1] foo      {{.*}}  AL  2
+# EXE-NEXT: [ 2] .text    {{.*}}  AX  0
+
+## An implementation detail: foo is moved after its linked-to section (orphan).
+# REL:      [Nr] Name     {{.*}} Flg Lk
+# REL-NEXT: [ 0]
+# REL-NEXT: [ 1] .text    {{.*}}  AX  0
+# REL-NEXT: [ 2] .text.f1 {{.*}}  AX  0
+# REL-NEXT: [ 3] foo      {{.*}}  AL  2
+# REL-NEXT: [ 4] .text.f2 {{.*}}  AX  0
+# REL-NEXT: [ 5] foo      {{.*}}  AL  4
+
+## A SECTIONS command combines .text.*
+# RUN: echo 'SECTIONS { .text : { *(.text.f1) *(.text.f2) } }' > %t1.lds
+# RUN: ld.lld -T %t1.lds %t.o -o %t1
+# RUN: llvm-readelf -S -x foo %t1 | FileCheck --check-prefixes=EXE,EXE-HEX %s
+# RUN: ld.lld -T %t1.lds %t.o -o %t1.ro -r
+# RUN: llvm-readelf -S -x foo %t1.ro | FileCheck --check-prefix=REL1 %s
+
+# REL1:      [Nr] Name    {{.*}} Flg Lk
+# REL1-NEXT: [ 0]
+# REL1-NEXT: [ 1] .text   {{.*}}  AX  0
+# REL1-NEXT: [ 2] foo     {{.*}}  AL  1
+
+## A SECTIONS command separates .text.*
+# RUN: echo 'SECTIONS { .text.f1 : { *(.text.f1) } .text.f2 : { *(.text.f2) } }' > %t2.lds
+# RUN: ld.lld -T %t2.lds %t.o -o %t2
+# RUN: llvm-readelf -S -x foo %t2 | FileCheck --check-prefixes=EXE2,EXE-HEX %s
+# RUN: ld.lld -T %t2.lds %t.o -o %t2.ro -r
+# RUN: llvm-readelf -S %t2.ro | FileCheck --check-prefixes=REL2 %s
+
+# EXE2:      [Nr] Name     {{.*}} Flg Lk
+# EXE2-NEXT: [ 0]
+# EXE2-NEXT: [ 1] foo      {{.*}}  AL  2
+# EXE2-NEXT: [ 2] .text.f1 {{.*}}  AX  0
+# EXE2-NEXT: [ 3] .text.f2 {{.*}}  AX  0
+
+# REL2:      [Nr] Name     {{.*}} Flg Lk
+# REL2-NEXT: [ 0]
+# REL2-NEXT: [ 1] .text.f1 {{.*}}  AX  0
+# REL2-NEXT: [ 2] .text.f2 {{.*}}  AX  0
+# REL2-NEXT: [ 3] .text    {{.*}}  AX  0
+# REL2-NEXT: [ 4] foo      {{.*}}  AL  1
+# REL2-NEXT: [ 5] foo      {{.*}}  AL  2
+
+# EXE-HEX:      Hex dump of section 'foo':
+# EXE-HEX-NEXT: 0102
+
+.section .text.f1,"ax", at progbits
+ret
+.section .text.f2,"ax", at progbits
+ret
+
+.section foo,"ao", at progbits,.text.f2
+.byte 2
+.section foo,"ao", at progbits,.text.f1
+.byte 1

diff  --git a/lld/test/ELF/relocatable-linkorder.s b/lld/test/ELF/relocatable-linkorder.s
deleted file mode 100644
index 0a7dfc6c12a2..000000000000
--- a/lld/test/ELF/relocatable-linkorder.s
+++ /dev/null
@@ -1,36 +0,0 @@
-// REQUIRES: x86
-// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux
-// RUN: ld.lld %t.o -o %t -r
-// RUN: llvm-readelf -S %t | FileCheck --check-prefix=DIFFERENT %s
-// RUN: echo 'SECTIONS { .text.f1 : { *(.text.f1) } .text.f2 : { *(.text.f2) } }' > %t.lds
-// RUN: ld.lld %t.o -o %t -r %t.lds
-// RUN: llvm-readelf -S %t | FileCheck --check-prefix=DIFFERENT %s
-// RUN: echo 'SECTIONS { .text : { *(.text.f1) *(.text.f2) } }' > %t.lds
-// RUN: ld.lld %t.o -o %t -r %t.lds
-// RUN: llvm-readelf -S -x foo %t | FileCheck --check-prefix=SAME %s
-
-/// Test that SHF_LINK_ORDER sections with 
diff erent linked sections
-/// aren't merged.
-
-.section .text.f1,"ax", at progbits
-.globl f1
-f1:
-ret
-
-.section .text.f2,"ax", at progbits
-.globl f2
-f2:
-ret
-
-// SAME: foo
-// DIFFERENT: foo
-.section foo,"ao", at progbits,.text.f2,unique,2
-.quad 2
-
-// SAME-NOT: foo
-// DIFFERENT: foo
-.section foo,"ao", at progbits,.text.f1,unique,1
-.quad 1
-
-// SAME: Hex dump of section 'foo':
-// SAME: 01000000 00000000 02000000 00000000


        


More information about the llvm-commits mailing list