Index: ELF/Driver.h =================================================================== --- ELF/Driver.h +++ ELF/Driver.h @@ -39,9 +39,6 @@ // True if we are in --whole-archive and --no-whole-archive. bool InWholeArchive = false; - // True if we are in --start-lib and --end-lib. - bool InLib = false; - // True if we are in -format=binary and -format=elf. bool InBinary = false; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -236,7 +236,7 @@ return; case file_magic::bitcode: case file_magic::elf_relocatable: - if (InLib) + if (InputFile::IsInLib) Files.push_back(make(MBRef, "", 0)); else Files.push_back(createObjectFile(MBRef)); @@ -990,10 +990,12 @@ ++InputFile::NextGroupId; break; case OPT_start_lib: - InLib = true; + InputFile::IsInLib = true; break; case OPT_end_lib: - InLib = false; + InputFile::IsInLib = false; + if (!InputFile::IsInGroup) + ++InputFile::NextGroupId; break; } } Index: ELF/InputFiles.h =================================================================== --- ELF/InputFiles.h +++ ELF/InputFiles.h @@ -113,13 +113,16 @@ 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; + // True if we are in --start-lib and --end-lib. + static bool IsInLib; + protected: InputFile(Kind K, MemoryBufferRef M); std::vector Sections; Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -40,6 +40,7 @@ bool InputFile::IsInGroup; uint32_t InputFile::NextGroupId; +bool InputFile::IsInLib; std::vector elf::BinaryFiles; std::vector elf::BitcodeFiles; std::vector elf::ObjectFiles; @@ -51,7 +52,7 @@ : MB(M), GroupId(NextGroupId), FileKind(K) { // All files within the same --{start,end}-group get the same group ID. // Otherwise, a new file will get a new group ID. - if (!IsInGroup) + if (!IsInGroup && !IsInLib) ++NextGroupId; } 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