[PATCH] D45849: [ELF] --warn-backrefs: use the same GroupId for object files in the same --{start, end}-lib

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 19 17:11:40 PDT 2018


MaskRay updated this revision to Diff 143198.
MaskRay added a comment.

Treat --start-lib as --start-group when using --warn-backrefs


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D45849

Files:
  ELF/Driver.cpp
  ELF/InputFiles.h
  test/ELF/start-lib.s
  test/ELF/warn-backrefs.s


Index: test/ELF/warn-backrefs.s
===================================================================
--- test/ELF/warn-backrefs.s
+++ test/ELF/warn-backrefs.s
@@ -35,6 +35,10 @@
 # RUN: not ld.lld --fatal-warnings --end-group 2>&1 | FileCheck -check-prefix=END %s
 # END: stray --end-group
 
+# RUN: echo ".globl bar; bar:" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t3.o
+# RUN: echo ".globl foo; foo: call bar" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t4.o
+# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o --start-lib %t3.o %t4.o --end-lib
+
 .globl _start, foo
 _start:
   call foo
Index: test/ELF/start-lib.s
===================================================================
--- test/ELF/start-lib.s
+++ test/ELF/start-lib.s
@@ -21,5 +21,11 @@
 // TEST3-NOT: Name: bar
 // TEST3-NOT: Name: foo
 
+// RUN: not ld.lld -o %t3 %t1.o --start-lib --start-lib %t2.o 2>&1 | FileCheck -check-prefix=NESTED-LIB %s
+// NESTED-LIB: nested --start-lib
+
+// RUN: not ld.lld -o %t3 %t1.o --start-group --start-lib %t2.o 2>&1 | FileCheck -check-prefix=LIB-IN-GROUP %s
+// LIB-IN-GROUP: may not nest --start-lib in --start-group
+
 .globl _start
 _start:
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -113,9 +113,9 @@
   bool JustSymbols = false;
 
   // GroupId is used for --warn-backrefs which is an optional error
-  // checking feature. All files within the same --{start,end}-group
-  // get the same group ID. Otherwise, each file gets a new group
-  // ID. For more info, see checkDependency() in SymbolTable.cpp.
+  // checking feature. All files within the same --{start,end}-group or
+  // --{start,end}-lib get the same group ID. Otherwise, each file gets a new
+  // group ID. For more info, see checkDependency() in SymbolTable.cpp.
   uint32_t GroupId;
   static bool IsInGroup;
   static uint32_t NextGroupId;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -990,10 +990,17 @@
       ++InputFile::NextGroupId;
       break;
     case OPT_start_lib:
+      if (InLib)
+        error("nested --start-lib");
+      if (InputFile::IsInGroup)
+        error("may not nest --start-lib in --start-group");
       InLib = true;
+      InputFile::IsInGroup = true;
       break;
     case OPT_end_lib:
       InLib = false;
+      InputFile::IsInGroup = false;
+      ++InputFile::NextGroupId;
       break;
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45849.143198.patch
Type: text/x-patch
Size: 2529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180420/ad0a5f77/attachment.bin>


More information about the llvm-commits mailing list