From: Fangrui Song Date: Tue, 25 Feb 2020 05:52:47 +0000 (-0800) Subject: [ELF] Support archive:file syntax in input section descriptions X-Git-Tag: llvmorg-12-init~13694 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=93331a17e8b3d6205efc8f1d4e7a74523f3b7035;p=platform%2Fupstream%2Fllvm.git [ELF] Support archive:file syntax in input section descriptions Fixes https://bugs.llvm.org/show_bug.cgi?id=44450 https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html#Input-Section-Basics The following two rules are not implemented. * `archive:` matches every file in the archive. * `:file` matches a file not in an archive. Reviewed By: grimar, ruiu Differential Revision: https://reviews.llvm.org/D75100 --- diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 9c9aacc..d78b490 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -323,7 +323,7 @@ static std::string getFilename(InputFile *file) { return ""; if (file->archiveName.empty()) return std::string(file->getName()); - return (file->archiveName + "(" + file->getName() + ")").str(); + return (file->archiveName + ':' + file->getName()).str(); } bool LinkerScript::shouldKeep(InputSectionBase *s) { diff --git a/lld/test/ELF/linkerscript/input-archive.s b/lld/test/ELF/linkerscript/input-archive.s new file mode 100644 index 0000000..f70f3c6 --- /dev/null +++ b/lld/test/ELF/linkerscript/input-archive.s @@ -0,0 +1,32 @@ +# REQUIRES: x86 +# UNSUPPORTED: system-windows +## Test that archive:file is supported in an input section description. + +# RUN: mkdir -p %t.dir +# RUN: echo '.data; .byte 1' | llvm-mc -filetype=obj -triple=x86_64 - -o %t.dir/a.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.dir/b.o +# RUN: rm -f %t.a +# RUN: llvm-ar rc %t.a %t.dir/a.o %t.dir/b.o + +## *.a:b.o matches /path/to/input-archive.s.tmp.a:b.o +## *b.o matches /path/to/input-archive.s.tmp.a:b.o +# RUN: echo 'SECTIONS { \ +# RUN: .foo : { %t.a:a.o(.data) } \ +# RUN: .bar : { *.a:b.o(.data) } \ +# RUN: .qux : { *b.o(.data1) } \ +# RUN: }' > %t.script +# RUN: ld.lld -T %t.script --whole-archive %t.a -o %t +# RUN: llvm-readelf -x .foo -x .bar -x .qux %t | FileCheck %s + +# CHECK: Hex dump of section '.foo': +# CHECK-NEXT: 0x00000000 01 +# CHECK: Hex dump of section '.bar': +# CHECK-NEXT: 0x00000001 02 +# CHECK: Hex dump of section '.qux': +# CHECK-NEXT: 0x00000002 03 + +.data +.byte 2 + +.section .data1,"aw",@progbits +.byte 3