Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion lib/Object/LibReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#include "eld/Object/LibReader.h"
#include "eld/Config/LinkerConfig.h"
#include "eld/Input/Input.h"
#include "eld/Input/InputFile.h"
#include "eld/Input/InputTree.h"
#include "eld/Object/ObjectLinker.h"
#include "eld/Support/MemoryArea.h"
#include "eld/Support/OutputTarWriter.h"
#include "eld/Support/RegisterTimer.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Twine.h"
Expand Down Expand Up @@ -83,6 +85,28 @@ bool LibReader::readLib(InputBuilder::InputIteratorT &CurNode,
if (!Input->resolvePath(Config))
return false;

// The synthetic archive below is what the linker processes, but the
// response file still names the original inputs between --start-lib and
// --end-lib. Capture those inputs explicitly for --reproduce; unlike a
// normal archive, the synthetic archive has no on-disk parent archive
// from which the reproducer can recover them.
if (MModule.getOutputTarWriter()) {
InputFile *InputFile = Input->getInputFile();
if (!InputFile) {
InputFile = eld::InputFile::create(Input, Config.getDiagEngine());
if (!InputFile)
return false;
Input->setInputFile(InputFile);
Comment thread
Steven6798 marked this conversation as resolved.
}
MappingFile::Kind Kind = InputFile->isBitcode()
? MappingFile::Kind::Bitcode
: MappingFile::Kind::ObjectFile;
InputFile->setMappedPath(Input->getName());
InputFile->setMappingFileKind(Kind);
MModule.getOutputTarWriter()->addInputFile(InputFile,
/*isLTOObject=*/false);
}

if (IsThin)
MemberNames.push_back(Input->getResolvedPath().getFullPath());
else
Expand Down Expand Up @@ -125,5 +149,16 @@ bool LibReader::readLib(InputBuilder::InputIteratorT &CurNode,
ArchiveInput->setMemberNameHash(Input::computeFilePathHash(ArchiveName));
ArchiveInput->setMemArea(MemArea);

return MObjLinker->readAndProcessInput(ArchiveInput, IsPostLtoPhase);
bool Success = MObjLinker->readAndProcessInput(ArchiveInput, IsPostLtoPhase);
if (Success && MModule.getOutputTarWriter() && ArchiveInput->getInputFile()) {
// Archive parsing populates the thin member list. Register the synthetic
// archive once more so its archive/member mapping is available during
// reproduction.
InputFile *ArchiveFile = ArchiveInput->getInputFile();
ArchiveFile->setMappedPath(ArchiveName);
ArchiveFile->setMappingFileKind(MappingFile::Kind::Archive);
MModule.getOutputTarWriter()->addInputFile(ArchiveFile,
/*isLTOObject=*/false);
}
return Success;
}
9 changes: 8 additions & 1 deletion test/Common/LTO/StartLibEndLib/StartLibEndLibLTO.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ RUN: %clang %clangopts -flto -c %p/Inputs/main.c -o %t.main.o

RUN: %link %linkopts %t.main.o --start-lib %t.foo.o %t.bar.o %t.baz.o --end-lib -o %t.out --print-timing-stats 2>&1 | %filecheck %s -check-prefix=TIMING

# Verify that an LTO --start-lib reproducer can be replayed.
RUN: %link %linkopts %t.main.o --start-lib %t.foo.o %t.bar.o %t.baz.o --end-lib -o %t.reproduce.out --reproduce %t.reproduce.tar --dump-response-file %t.reproduce.response
RUN: %mkdir %t.reproduce
RUN: cd %t.reproduce
RUN: %tar %gnutaropts -xf %t.reproduce.tar --strip-components=1
RUN: %link @response.txt -o %t.replay.out
RUN: %diff %t.reproduce.out %t.replay.out

#TIMING: Build --start-lib archive
#TIMING-NOT: Build --start-lib archive
#END_TEST

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ RUN: %filecheck %s -check-prefix=SCRIPT-MAP < %t.script.map.txt
RUN: %link -o %t.group.out %linkopts %t.main_group.o --start-group --start-lib %t.fcb.o %t.baz_impl.o --end-lib %t.libbar.a --end-group
RUN: %nm %t.group.out | %filecheck %s -check-prefix=GROUPSYM

# Verify that the generated response and archive can be replayed for
# --start-lib. The original member must be captured even though the linker
# processes the synthetic archive.
RUN: %link -o %t.reproduce.out %linkopts %t.main.o --start-lib %t.foo.o --end-lib --reproduce %t.reproduce.tar --dump-response-file %t.reproduce.response
RUN: %mkdir %t.reproduce
RUN: cd %t.reproduce
RUN: %tar %gnutaropts -xf %t.reproduce.tar --strip-components=1
RUN: %link @response.txt -o %t.replay.out
RUN: %diff %t.reproduce.out %t.replay.out

#MISMATCH: Mismatched --start-lib/--end-lib
#NEST: Nested --start-lib/--end-lib not allowed
#SYM: foo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ RUN: %clang %clangopts -c %p/Inputs/main_script.c -o %t.main_script.o -ffunction
RUN: %link -o %t.script.out %linkopts %t.main_script.o --start-lib-thin %t.foo_sel.o %t.bar_sel.o --end-lib-thin -T %p/Inputs/startlib_thin_archive_pattern.t -MapStyle txt -Map %t.script.map.txt
RUN: %filecheck %s -check-prefix=SCRIPT-MAP-THIN < %t.script.map.txt

# Verify replay of a thin --start-lib reproducer, including its original
# object-file members.
RUN: %link -o %t.reproduce.out %linkopts %t.main_multi.o --start-lib-thin %t.foo.o %t.bar.o %t.baz.o --end-lib-thin --reproduce %t.reproduce.tar --dump-response-file %t.reproduce.response
RUN: %mkdir %t.reproduce
RUN: cd %t.reproduce
RUN: %tar %gnutaropts -xf %t.reproduce.tar --strip-components=1
RUN: %link @response.txt -o %t.replay.out
RUN: %diff %t.reproduce.out %t.replay.out

#MULTI-SYM-THIN-DAG: foo
#MULTI-SYM-THIN-DAG: bar
#WHOLE-SYM-THIN-DAG: foo
Expand All @@ -31,4 +40,3 @@ RUN: %filecheck %s -check-prefix=SCRIPT-MAP-THIN < %t.script.map.txt
#SCRIPT-MAP-THIN: .bar_out
#SCRIPT-MAP-THIN: "*<start-lib-thin:1>:*bar_sel.o"
#END_TEST

Loading