[lld] r261726 - [ELF] - Teach input section wildcard patterns to recognize '?' meta character.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 24 00:56:05 PST 2016
Author: grimar
Date: Wed Feb 24 02:49:50 2016
New Revision: 261726
URL: http://llvm.org/viewvc/llvm-project?rev=261726&view=rev
Log:
[ELF] - Teach input section wildcard patterns to recognize '?' meta character.
`?' - matches any single character
https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html
This is used in linker scripts.
Differential revision: http://reviews.llvm.org/D17290
Added:
lld/trunk/test/ELF/wildcards.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/linkerscript-sections.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=261726&r1=261725&r2=261726&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Feb 24 02:49:50 2016
@@ -66,8 +66,9 @@ int LinkerScript::compareSections(String
return I < J ? -1 : 1;
}
-// Returns true if S matches T. S may contain a meta character '*'
-// which matches zero or more occurrences of any character.
+// Returns true if S matches T. S can contain glob meta-characters.
+// The asterisk ('*') matches zero or more characacters, and the question
+// mark ('?') matches one character.
static bool matchStr(StringRef S, StringRef T) {
for (;;) {
if (S.empty())
@@ -82,7 +83,7 @@ static bool matchStr(StringRef S, String
return true;
return false;
}
- if (T.empty() || S[0] != T[0])
+ if (T.empty() || (S[0] != T[0] && S[0] != '?'))
return false;
S = S.substr(1);
T = T.substr(1);
Modified: lld/trunk/test/ELF/linkerscript-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript-sections.s?rev=261726&r1=261725&r2=261726&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript-sections.s (original)
+++ lld/trunk/test/ELF/linkerscript-sections.s Wed Feb 24 02:49:50 2016
@@ -38,20 +38,6 @@
# RUN: llvm-objdump -section-headers %t3 | \
# RUN: FileCheck -check-prefix=SEC-ORDER %s
-# The same test as above but with wildcard patterns.
-# RUN: echo "SECTIONS { \
-# RUN: .bss : { *(.bss) } \
-# RUN: other : { *(o*er) } \
-# RUN: .shstrtab : { *(.shstrt*) } \
-# RUN: .symtab : { *(.symtab) } \
-# RUN: .strtab : { *(.strtab) } \
-# RUN: .data : { *(*data) } \
-# RUN: .text : { *(.text) } }" > %t.script
-# RUN: cp %t %t.abc
-# RUN: ld.lld -o %t3 --script %t.script %t.abc
-# RUN: llvm-objdump -section-headers %t3 | \
-# RUN: FileCheck -check-prefix=SEC-ORDER %s
-
# Idx Name Size
# SEC-ORDER: 1 .bss 00000002 {{[0-9a-f]*}} BSS
# SEC-ORDER: 2 other 00000003 {{[0-9a-f]*}} DATA
Added: lld/trunk/test/ELF/wildcards.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/wildcards.s?rev=261726&view=auto
==============================================================================
--- lld/trunk/test/ELF/wildcards.s (added)
+++ lld/trunk/test/ELF/wildcards.s Wed Feb 24 02:49:50 2016
@@ -0,0 +1,80 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+
+## Default case: abc and abx included in text.
+# RUN: echo "SECTIONS { \
+# RUN: .text : { *(.abc .abx) } }" > %t.script
+# RUN: ld.lld -o %t.out --script %t.script %t
+# RUN: llvm-objdump -section-headers %t.out | \
+# RUN: FileCheck -check-prefix=SEC-DEFAULT %s
+# SEC-DEFAULT: Sections:
+# SEC-DEFAULT-NEXT: Idx Name Size Address Type
+# SEC-DEFAULT-NEXT: 0 00000000 0000000000000000
+# SEC-DEFAULT-NEXT: 1 .text 00000008 0000000000011000 TEXT DATA
+# SEC-DEFAULT-NEXT: 2 .abcd 00000004 0000000000011008 TEXT DATA
+# SEC-DEFAULT-NEXT: 3 .ad 00000004 000000000001100c TEXT DATA
+# SEC-DEFAULT-NEXT: 4 .ag 00000004 0000000000011010 TEXT DATA
+# SEC-DEFAULT-NEXT: 5 .symtab 00000030 0000000000000000
+# SEC-DEFAULT-NEXT: 6 .shstrtab 0000002f 0000000000000000
+# SEC-DEFAULT-NEXT: 7 .strtab 00000008 0000000000000000
+
+## Now replace the symbol with '?' and check that results are the same.
+# RUN: echo "SECTIONS { \
+# RUN: .text : { *(.abc .ab?) } }" > %t.script
+# RUN: ld.lld -o %t.out --script %t.script %t
+# RUN: llvm-objdump -section-headers %t.out | \
+# RUN: FileCheck -check-prefix=SEC-DEFAULT %s
+
+## Now see how replacing '?' with '*' will consume whole abcd.
+# RUN: echo "SECTIONS { \
+# RUN: .text : { *(.abc .ab*) } }" > %t.script
+# RUN: ld.lld -o %t.out --script %t.script %t
+# RUN: llvm-objdump -section-headers %t.out | \
+# RUN: FileCheck -check-prefix=SEC-ALL %s
+# SEC-ALL: Sections:
+# SEC-ALL-NEXT: Idx Name Size Address Type
+# SEC-ALL-NEXT: 0 00000000 0000000000000000
+# SEC-ALL-NEXT: 1 .text 0000000c 0000000000011000 TEXT DATA
+# SEC-ALL-NEXT: 2 .ad 00000004 000000000001100c TEXT DATA
+# SEC-ALL-NEXT: 3 .ag 00000004 0000000000011010 TEXT DATA
+# SEC-ALL-NEXT: 4 .symtab 00000030 0000000000000000
+# SEC-ALL-NEXT: 5 .shstrtab 00000029 0000000000000000
+# SEC-ALL-NEXT: 6 .strtab 00000008 0000000000000000
+
+## All sections started with .a are merged.
+# RUN: echo "SECTIONS { \
+# RUN: .text : { *(.a*) } }" > %t.script
+# RUN: ld.lld -o %t.out --script %t.script %t
+# RUN: llvm-objdump -section-headers %t.out | \
+# RUN: FileCheck -check-prefix=SEC-NO %s
+# SEC-NO: Sections:
+# SEC-NO-NEXT: Idx Name Size Address Type
+# SEC-NO-NEXT: 0 00000000 0000000000000000
+# SEC-NO-NEXT: 1 .text 00000014 0000000000011000 TEXT DATA
+# SEC-NO-NEXT: 2 .symtab 00000030 0000000000000000
+# SEC-NO-NEXT: 3 .shstrtab 00000021 0000000000000000
+# SEC-NO-NEXT: 4 .strtab 00000008 0000000000000000
+
+.text
+.section .abc,"ax", at progbits
+.long 0
+
+.text
+.section .abx,"ax", at progbits
+.long 0
+
+.text
+.section .abcd,"ax", at progbits
+.long 0
+
+.text
+.section .ad,"ax", at progbits
+.long 0
+
+.text
+.section .ag,"ax", at progbits
+.long 0
+
+
+.globl _start
+_start:
More information about the llvm-commits
mailing list