Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ScriptParser/ScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ InputSectDesc::Spec ScriptParser::readInputSectionDescSpec(StringRef Tok) {
if (!Tok.contains(':'))
FilePat = createAndRegisterWildcardPattern(Tok);
else {
// We cannot store the original quote information because we represent
// the single token "archive:mem" in the linker script as two separate
// patterns in the linker codebase.
Tok = unquote(Tok);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use createParserStr to preserve the property that the input token had a quote.

The map file might not show information about quotes from the linker script or the linker script generator too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createParserStr alone would not be helpful here. We do use createParserStr within createAndRegisterWildcardPattern. The issue is that a single quoted token ("archive:mem") is stored as two separate tokens -- archive file pattern and member pattern -- in the linker codebase. It would be incorrect to store both archive file pattern and the member pattern with quotes if the original combined pattern was with quotes because "archive":"mem" would be interpreted differently from "archive:mem".

std::pair<llvm::StringRef, llvm::StringRef> Split = Tok.split(':');
FilePat = createAndRegisterWildcardPattern(Split.first);
if (!Split.second.empty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
int foo() { return 1; }

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int foo();
int main() { return foo(); }

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SECTIONS {
.foo : { "*lib1.a:*1.o"(.text*) }
.text : { *(.text*) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#---QuotedArchiveMemberPattern.test--------------------- Executable ------------------#
#BEGIN_COMMENT
# Validates that a quoted archive:member file pattern in an input section
# description is interpreted correctly.
#END_COMMENT
RUN: %clang %clangopts -o %t1.1.o %p/Inputs/1.c -c -ffunction-sections
RUN: %clang %clangopts -o %t1.main.o %p/Inputs/main.c -c -ffunction-sections
RUN: %ar cr %t1.lib1.a %t1.1.o
RUN: %link %linkopts -o %t1.main.out %t1.main.o %t1.lib1.a -MapStyle txt -T %p/Inputs/script.t -Map %t1.main.map.txt
RUN: %filecheck %s --check-prefix MAP < %t1.main.map.txt
RUN: %readelf -S %t1.main.out | %filecheck %s --check-prefix SECT

MAP: .foo {{.*}} # Offset
MAP: *lib1.a:*1.o
MAP: .text.foo
MAP: foo
MAP: .text {{.*}} # Offset

SECT: .foo PROGBITS
Loading