@@ -1759,7 +1759,10 @@ static uint8_t getOsAbi(const Triple &t) {
17591759// Returns true if adjusted; false otherwise. Non-thin archives are unsupported.
17601760static bool dtltoAdjustMemberPathIfThinArchive (Ctx &ctx, StringRef archivePath,
17611761 std::string &memberPath) {
1762- assert (!archivePath.empty () && !ctx.arg .dtltoDistributor .empty ());
1762+ assert (!archivePath.empty ());
1763+
1764+ if (ctx.arg .dtltoDistributor .empty ())
1765+ return false ;
17631766
17641767 // Read the archive header to determine if it's a thin archive.
17651768 auto bufferOrErr =
@@ -1794,20 +1797,22 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
17941797 if (ctx.arg .thinLTOIndexOnly )
17951798 path = replaceThinLTOSuffix (ctx, mb.getBufferIdentifier ());
17961799
1797- // ThinLTO assumes that all MemoryBufferRefs given to it have a unique
1798- // name. If two archives define two members with the same name, this
1799- // causes a collision which result in only one of the objects being taken
1800- // into consideration at LTO time (which very likely causes undefined
1801- // symbols later in the link stage). So we append file offset to make
1802- // filename unique.
18031800 StringSaver &ss = ctx.saver ;
1804- StringRef name =
1805- (archiveName.empty () ||
1806- (!ctx.arg .dtltoDistributor .empty () &&
1807- dtltoAdjustMemberPathIfThinArchive (ctx, archiveName, path)))
1808- ? ss.save (path)
1809- : ss.save (archiveName + " (" + path::filename (path) + " at " +
1810- utostr (offsetInArchive) + " )" );
1801+ StringRef name;
1802+ if (archiveName.empty () ||
1803+ dtltoAdjustMemberPathIfThinArchive (ctx, archiveName, path)) {
1804+ name = ss.save (path);
1805+ } else {
1806+ // ThinLTO assumes that all MemoryBufferRefs given to it have a unique
1807+ // name. If two archives define two members with the same name, this
1808+ // causes a collision which result in only one of the objects being taken
1809+ // into consideration at LTO time (which very likely causes undefined
1810+ // symbols later in the link stage). So we append file offset to make
1811+ // filename unique.
1812+ name = ss.save (archiveName + " (" + path::filename (path) + " at " +
1813+ utostr (offsetInArchive) + " )" );
1814+ }
1815+
18111816 MemoryBufferRef mbref (mb.getBuffer (), name);
18121817
18131818 obj = CHECK2 (lto::InputFile::create (mbref), this );
0 commit comments