From 2416d7fcb2268a91c2717137a6f52b97983343bb Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 20 Apr 2018 16:33:01 +0000 Subject: [PATCH] [ELF] --warn-backrefs: use the same GroupId for object files in the same --{start,end}-lib Reviewers: ruiu, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D45849 llvm-svn: 330443 --- lld/ELF/Driver.cpp | 9 +++++++++ lld/ELF/InputFiles.h | 6 +++--- lld/test/ELF/start-lib.s | 9 +++++++++ lld/test/ELF/warn-backrefs.s | 4 ++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 4cbc701..ab3ab26 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -990,10 +990,19 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) { ++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: + if (!InLib) + error("stray --end-lib"); InLib = false; + InputFile::IsInGroup = false; + ++InputFile::NextGroupId; break; } } diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index cb6bccb..09bc34b 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -113,9 +113,9 @@ public: 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; diff --git a/lld/test/ELF/start-lib.s b/lld/test/ELF/start-lib.s index 013a2b2..b79d9ef 100644 --- a/lld/test/ELF/start-lib.s +++ b/lld/test/ELF/start-lib.s @@ -21,5 +21,14 @@ // TEST3-NOT: Name: bar // TEST3-NOT: Name: foo +// RUN: not ld.lld %t1.o --start-lib --start-lib 2>&1 | FileCheck -check-prefix=NESTED-LIB %s +// NESTED-LIB: nested --start-lib + +// RUN: not ld.lld %t1.o --start-group --start-lib 2>&1 | FileCheck -check-prefix=LIB-IN-GROUP %s +// LIB-IN-GROUP: may not nest --start-lib in --start-group + +// RUN: not ld.lld --end-lib 2>&1 | FileCheck -check-prefix=END %s +// END: stray --end-lib + .globl _start _start: diff --git a/lld/test/ELF/warn-backrefs.s b/lld/test/ELF/warn-backrefs.s index 192d7ee..4baeabc 100644 --- a/lld/test/ELF/warn-backrefs.s +++ b/lld/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 -- 2.7.4