[PATCH] D75100: [ELF] Support archive:file syntax in input section descriptions

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 24 22:43:47 PST 2020


MaskRay created this revision.
MaskRay added reviewers: grimar, john.brawn, psmith, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75100

Files:
  lld/ELF/LinkerScript.cpp
  lld/test/ELF/linkerscript/input-archive.s


Index: lld/test/ELF/linkerscript/input-archive.s
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/input-archive.s
@@ -0,0 +1,29 @@
+# REQUIRES: x86
+# 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", at progbits
+.byte 3
Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -323,7 +323,7 @@
     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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75100.246369.patch
Type: text/x-patch
Size: 1575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200225/5abb5c2a/attachment-0001.bin>


More information about the llvm-commits mailing list