1 //===- InputFiles.cpp -----------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "InputFiles.h"
10 #include "COFFLinkerContext.h"
13 #include "DebugTypes.h"
15 #include "SymbolTable.h"
17 #include "lld/Common/DWARF.h"
18 #include "llvm-c/lto.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/BinaryFormat/COFF.h"
22 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
23 #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
24 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
25 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
26 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
27 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
28 #include "llvm/LTO/LTO.h"
29 #include "llvm/Object/Binary.h"
30 #include "llvm/Object/COFF.h"
31 #include "llvm/Support/Casting.h"
32 #include "llvm/Support/Endian.h"
33 #include "llvm/Support/Error.h"
34 #include "llvm/Support/ErrorOr.h"
35 #include "llvm/Support/FileSystem.h"
36 #include "llvm/Support/Path.h"
37 #include "llvm/Target/TargetOptions.h"
38 #include "llvm/TargetParser/Triple.h"
41 #include <system_error>
45 using namespace llvm::COFF
;
46 using namespace llvm::codeview
;
47 using namespace llvm::object
;
48 using namespace llvm::support::endian
;
50 using namespace lld::coff
;
53 using llvm::support::ulittle32_t
;
55 // Returns the last element of a path, which is supposed to be a filename.
56 static StringRef
getBasename(StringRef path
) {
57 return sys::path::filename(path
, sys::path::Style::windows
);
60 // Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
61 std::string
lld::toString(const coff::InputFile
*file
) {
64 if (file
->parentName
.empty() || file
->kind() == coff::InputFile::ImportKind
)
65 return std::string(file
->getName());
67 return (getBasename(file
->parentName
) + "(" + getBasename(file
->getName()) +
72 /// Checks that Source is compatible with being a weak alias to Target.
73 /// If Source is Undefined and has no weak alias set, makes it a weak
75 static void checkAndSetWeakAlias(COFFLinkerContext
&ctx
, InputFile
*f
,
76 Symbol
*source
, Symbol
*target
) {
77 if (auto *u
= dyn_cast
<Undefined
>(source
)) {
78 if (u
->weakAlias
&& u
->weakAlias
!= target
) {
79 // Weak aliases as produced by GCC are named in the form
80 // .weak.<weaksymbol>.<othersymbol>, where <othersymbol> is the name
81 // of another symbol emitted near the weak symbol.
82 // Just use the definition from the first object file that defined
84 if (ctx
.config
.allowDuplicateWeak
)
86 ctx
.symtab
.reportDuplicate(source
, f
);
88 u
->weakAlias
= target
;
92 static bool ignoredSymbolName(StringRef name
) {
93 return name
== "@feat.00" || name
== "@comp.id";
96 ArchiveFile::ArchiveFile(COFFLinkerContext
&ctx
, MemoryBufferRef m
)
97 : InputFile(ctx
, ArchiveKind
, m
) {}
99 void ArchiveFile::parse() {
100 // Parse a MemoryBufferRef as an archive file.
101 file
= CHECK(Archive::create(mb
), this);
103 // Read the symbol table to construct Lazy objects.
104 for (const Archive::Symbol
&sym
: file
->symbols())
105 ctx
.symtab
.addLazyArchive(this, sym
);
108 // Returns a buffer pointing to a member file containing a given symbol.
109 void ArchiveFile::addMember(const Archive::Symbol
&sym
) {
110 const Archive::Child
&c
=
111 CHECK(sym
.getMember(),
112 "could not get the member for symbol " + toCOFFString(ctx
, sym
));
114 // Return an empty buffer if we have already returned the same buffer.
115 if (!seen
.insert(c
.getChildOffset()).second
)
118 ctx
.driver
.enqueueArchiveMember(c
, sym
, getName());
121 std::vector
<MemoryBufferRef
> lld::coff::getArchiveMembers(Archive
*file
) {
122 std::vector
<MemoryBufferRef
> v
;
123 Error err
= Error::success();
124 for (const Archive::Child
&c
: file
->children(err
)) {
125 MemoryBufferRef mbref
=
126 CHECK(c
.getMemoryBufferRef(),
127 file
->getFileName() +
128 ": could not get the buffer for a child of the archive");
132 fatal(file
->getFileName() +
133 ": Archive::children failed: " + toString(std::move(err
)));
137 void ObjFile::parseLazy() {
138 // Native object file.
139 std::unique_ptr
<Binary
> coffObjPtr
= CHECK(createBinary(mb
), this);
140 COFFObjectFile
*coffObj
= cast
<COFFObjectFile
>(coffObjPtr
.get());
141 uint32_t numSymbols
= coffObj
->getNumberOfSymbols();
142 for (uint32_t i
= 0; i
< numSymbols
; ++i
) {
143 COFFSymbolRef coffSym
= check(coffObj
->getSymbol(i
));
144 if (coffSym
.isUndefined() || !coffSym
.isExternal() ||
145 coffSym
.isWeakExternal())
147 StringRef name
= check(coffObj
->getSymbolName(coffSym
));
148 if (coffSym
.isAbsolute() && ignoredSymbolName(name
))
150 ctx
.symtab
.addLazyObject(this, name
);
151 i
+= coffSym
.getNumberOfAuxSymbols();
161 void ObjFile::initializeECThunks() {
162 for (SectionChunk
*chunk
: hybmpChunks
) {
163 if (chunk
->getContents().size() % sizeof(ECMapEntry
)) {
164 error("Invalid .hybmp chunk size " + Twine(chunk
->getContents().size()));
169 chunk
->getContents().data() + chunk
->getContents().size();
170 for (const uint8_t *iter
= chunk
->getContents().data(); iter
!= end
;
171 iter
+= sizeof(ECMapEntry
)) {
172 auto entry
= reinterpret_cast<const ECMapEntry
*>(iter
);
173 switch (entry
->type
) {
174 case Arm64ECThunkType::Entry
:
175 ctx
.symtab
.addEntryThunk(getSymbol(entry
->src
), getSymbol(entry
->dst
));
177 case Arm64ECThunkType::Exit
:
178 case Arm64ECThunkType::GuestExit
:
181 warn("Ignoring unknown EC thunk type " + Twine(entry
->type
));
187 void ObjFile::parse() {
188 // Parse a memory buffer as a COFF file.
189 std::unique_ptr
<Binary
> bin
= CHECK(createBinary(mb
), this);
191 if (auto *obj
= dyn_cast
<COFFObjectFile
>(bin
.get())) {
195 fatal(toString(this) + " is not a COFF file");
198 // Read section and symbol tables.
202 initializeDependencies();
203 initializeECThunks();
206 const coff_section
*ObjFile::getSection(uint32_t i
) {
207 auto sec
= coffObj
->getSection(i
);
209 fatal("getSection failed: #" + Twine(i
) + ": " + toString(sec
.takeError()));
213 // We set SectionChunk pointers in the SparseChunks vector to this value
214 // temporarily to mark comdat sections as having an unknown resolution. As we
215 // walk the object file's symbol table, once we visit either a leader symbol or
216 // an associative section definition together with the parent comdat's leader,
217 // we set the pointer to either nullptr (to mark the section as discarded) or a
218 // valid SectionChunk for that section.
219 static SectionChunk
*const pendingComdat
= reinterpret_cast<SectionChunk
*>(1);
221 void ObjFile::initializeChunks() {
222 uint32_t numSections
= coffObj
->getNumberOfSections();
223 sparseChunks
.resize(numSections
+ 1);
224 for (uint32_t i
= 1; i
< numSections
+ 1; ++i
) {
225 const coff_section
*sec
= getSection(i
);
226 if (sec
->Characteristics
& IMAGE_SCN_LNK_COMDAT
)
227 sparseChunks
[i
] = pendingComdat
;
229 sparseChunks
[i
] = readSection(i
, nullptr, "");
233 SectionChunk
*ObjFile::readSection(uint32_t sectionNumber
,
234 const coff_aux_section_definition
*def
,
235 StringRef leaderName
) {
236 const coff_section
*sec
= getSection(sectionNumber
);
239 if (Expected
<StringRef
> e
= coffObj
->getSectionName(sec
))
242 fatal("getSectionName failed: #" + Twine(sectionNumber
) + ": " +
243 toString(e
.takeError()));
245 if (name
== ".drectve") {
246 ArrayRef
<uint8_t> data
;
247 cantFail(coffObj
->getSectionContents(sec
, data
));
248 directives
= StringRef((const char *)data
.data(), data
.size());
252 if (name
== ".llvm_addrsig") {
257 if (name
== ".llvm.call-graph-profile") {
262 // Object files may have DWARF debug info or MS CodeView debug info
265 // DWARF sections don't need any special handling from the perspective
266 // of the linker; they are just a data section containing relocations.
267 // We can just link them to complete debug info.
269 // CodeView needs linker support. We need to interpret debug info,
270 // and then write it to a separate .pdb file.
272 // Ignore DWARF debug info unless requested to be included.
273 if (!ctx
.config
.includeDwarfChunks
&& name
.starts_with(".debug_"))
276 if (sec
->Characteristics
& llvm::COFF::IMAGE_SCN_LNK_REMOVE
)
279 if (isArm64EC(getMachineType()))
280 c
= make
<SectionChunkEC
>(this, sec
);
282 c
= make
<SectionChunk
>(this, sec
);
284 c
->checksum
= def
->CheckSum
;
286 // CodeView sections are stored to a different vector because they are not
287 // linked in the regular manner.
289 debugChunks
.push_back(c
);
290 else if (name
== ".gfids$y")
291 guardFidChunks
.push_back(c
);
292 else if (name
== ".giats$y")
293 guardIATChunks
.push_back(c
);
294 else if (name
== ".gljmp$y")
295 guardLJmpChunks
.push_back(c
);
296 else if (name
== ".gehcont$y")
297 guardEHContChunks
.push_back(c
);
298 else if (name
== ".sxdata")
299 sxDataChunks
.push_back(c
);
300 else if (isArm64EC(getMachineType()) && name
== ".hybmp$x")
301 hybmpChunks
.push_back(c
);
302 else if (ctx
.config
.tailMerge
&& sec
->NumberOfRelocations
== 0 &&
303 name
== ".rdata" && leaderName
.starts_with("??_C@"))
304 // COFF sections that look like string literal sections (i.e. no
305 // relocations, in .rdata, leader symbol name matches the MSVC name mangling
306 // for string literals) are subject to string tail merging.
307 MergeChunk::addSection(ctx
, c
);
308 else if (name
== ".rsrc" || name
.starts_with(".rsrc$"))
309 resourceChunks
.push_back(c
);
316 void ObjFile::includeResourceChunks() {
317 chunks
.insert(chunks
.end(), resourceChunks
.begin(), resourceChunks
.end());
320 void ObjFile::readAssociativeDefinition(
321 COFFSymbolRef sym
, const coff_aux_section_definition
*def
) {
322 readAssociativeDefinition(sym
, def
, def
->getNumber(sym
.isBigObj()));
325 void ObjFile::readAssociativeDefinition(COFFSymbolRef sym
,
326 const coff_aux_section_definition
*def
,
327 uint32_t parentIndex
) {
328 SectionChunk
*parent
= sparseChunks
[parentIndex
];
329 int32_t sectionNumber
= sym
.getSectionNumber();
332 StringRef name
= check(coffObj
->getSymbolName(sym
));
334 StringRef parentName
;
335 const coff_section
*parentSec
= getSection(parentIndex
);
336 if (Expected
<StringRef
> e
= coffObj
->getSectionName(parentSec
))
338 error(toString(this) + ": associative comdat " + name
+ " (sec " +
339 Twine(sectionNumber
) + ") has invalid reference to section " +
340 parentName
+ " (sec " + Twine(parentIndex
) + ")");
343 if (parent
== pendingComdat
) {
344 // This can happen if an associative comdat refers to another associative
345 // comdat that appears after it (invalid per COFF spec) or to a section
346 // without any symbols.
351 // Check whether the parent is prevailing. If it is, so are we, and we read
352 // the section; otherwise mark it as discarded.
354 SectionChunk
*c
= readSection(sectionNumber
, def
, "");
355 sparseChunks
[sectionNumber
] = c
;
357 c
->selection
= IMAGE_COMDAT_SELECT_ASSOCIATIVE
;
358 parent
->addAssociative(c
);
361 sparseChunks
[sectionNumber
] = nullptr;
365 void ObjFile::recordPrevailingSymbolForMingw(
366 COFFSymbolRef sym
, DenseMap
<StringRef
, uint32_t> &prevailingSectionMap
) {
367 // For comdat symbols in executable sections, where this is the copy
368 // of the section chunk we actually include instead of discarding it,
369 // add the symbol to a map to allow using it for implicitly
370 // associating .[px]data$<func> sections to it.
371 // Use the suffix from the .text$<func> instead of the leader symbol
372 // name, for cases where the names differ (i386 mangling/decorations,
373 // cases where the leader is a weak symbol named .weak.func.default*).
374 int32_t sectionNumber
= sym
.getSectionNumber();
375 SectionChunk
*sc
= sparseChunks
[sectionNumber
];
376 if (sc
&& sc
->getOutputCharacteristics() & IMAGE_SCN_MEM_EXECUTE
) {
377 StringRef name
= sc
->getSectionName().split('$').second
;
378 prevailingSectionMap
[name
] = sectionNumber
;
382 void ObjFile::maybeAssociateSEHForMingw(
383 COFFSymbolRef sym
, const coff_aux_section_definition
*def
,
384 const DenseMap
<StringRef
, uint32_t> &prevailingSectionMap
) {
385 StringRef name
= check(coffObj
->getSymbolName(sym
));
386 if (name
.consume_front(".pdata$") || name
.consume_front(".xdata$") ||
387 name
.consume_front(".eh_frame$")) {
388 // For MinGW, treat .[px]data$<func> and .eh_frame$<func> as implicitly
389 // associative to the symbol <func>.
390 auto parentSym
= prevailingSectionMap
.find(name
);
391 if (parentSym
!= prevailingSectionMap
.end())
392 readAssociativeDefinition(sym
, def
, parentSym
->second
);
396 Symbol
*ObjFile::createRegular(COFFSymbolRef sym
) {
397 SectionChunk
*sc
= sparseChunks
[sym
.getSectionNumber()];
398 if (sym
.isExternal()) {
399 StringRef name
= check(coffObj
->getSymbolName(sym
));
401 return ctx
.symtab
.addRegular(this, name
, sym
.getGeneric(), sc
,
403 // For MinGW symbols named .weak.* that point to a discarded section,
404 // don't create an Undefined symbol. If nothing ever refers to the symbol,
405 // everything should be fine. If something actually refers to the symbol
406 // (e.g. the undefined weak alias), linking will fail due to undefined
407 // references at the end.
408 if (ctx
.config
.mingw
&& name
.starts_with(".weak."))
410 return ctx
.symtab
.addUndefined(name
, this, false);
413 return make
<DefinedRegular
>(this, /*Name*/ "", /*IsCOMDAT*/ false,
414 /*IsExternal*/ false, sym
.getGeneric(), sc
);
418 void ObjFile::initializeSymbols() {
419 uint32_t numSymbols
= coffObj
->getNumberOfSymbols();
420 symbols
.resize(numSymbols
);
422 SmallVector
<std::pair
<Symbol
*, uint32_t>, 8> weakAliases
;
423 std::vector
<uint32_t> pendingIndexes
;
424 pendingIndexes
.reserve(numSymbols
);
426 DenseMap
<StringRef
, uint32_t> prevailingSectionMap
;
427 std::vector
<const coff_aux_section_definition
*> comdatDefs(
428 coffObj
->getNumberOfSections() + 1);
430 for (uint32_t i
= 0; i
< numSymbols
; ++i
) {
431 COFFSymbolRef coffSym
= check(coffObj
->getSymbol(i
));
432 bool prevailingComdat
;
433 if (coffSym
.isUndefined()) {
434 symbols
[i
] = createUndefined(coffSym
);
435 } else if (coffSym
.isWeakExternal()) {
436 symbols
[i
] = createUndefined(coffSym
);
437 uint32_t tagIndex
= coffSym
.getAux
<coff_aux_weak_external
>()->TagIndex
;
438 weakAliases
.emplace_back(symbols
[i
], tagIndex
);
439 } else if (std::optional
<Symbol
*> optSym
=
440 createDefined(coffSym
, comdatDefs
, prevailingComdat
)) {
441 symbols
[i
] = *optSym
;
442 if (ctx
.config
.mingw
&& prevailingComdat
)
443 recordPrevailingSymbolForMingw(coffSym
, prevailingSectionMap
);
445 // createDefined() returns std::nullopt if a symbol belongs to a section
446 // that was pending at the point when the symbol was read. This can happen
448 // 1) section definition symbol for a comdat leader;
449 // 2) symbol belongs to a comdat section associated with another section.
450 // In both of these cases, we can expect the section to be resolved by
451 // the time we finish visiting the remaining symbols in the symbol
452 // table. So we postpone the handling of this symbol until that time.
453 pendingIndexes
.push_back(i
);
455 i
+= coffSym
.getNumberOfAuxSymbols();
458 for (uint32_t i
: pendingIndexes
) {
459 COFFSymbolRef sym
= check(coffObj
->getSymbol(i
));
460 if (const coff_aux_section_definition
*def
= sym
.getSectionDefinition()) {
461 if (def
->Selection
== IMAGE_COMDAT_SELECT_ASSOCIATIVE
)
462 readAssociativeDefinition(sym
, def
);
463 else if (ctx
.config
.mingw
)
464 maybeAssociateSEHForMingw(sym
, def
, prevailingSectionMap
);
466 if (sparseChunks
[sym
.getSectionNumber()] == pendingComdat
) {
467 StringRef name
= check(coffObj
->getSymbolName(sym
));
468 log("comdat section " + name
+
469 " without leader and unassociated, discarding");
472 symbols
[i
] = createRegular(sym
);
475 for (auto &kv
: weakAliases
) {
476 Symbol
*sym
= kv
.first
;
477 uint32_t idx
= kv
.second
;
478 checkAndSetWeakAlias(ctx
, this, sym
, symbols
[idx
]);
481 // Free the memory used by sparseChunks now that symbol loading is finished.
482 decltype(sparseChunks
)().swap(sparseChunks
);
485 Symbol
*ObjFile::createUndefined(COFFSymbolRef sym
) {
486 StringRef name
= check(coffObj
->getSymbolName(sym
));
487 return ctx
.symtab
.addUndefined(name
, this, sym
.isWeakExternal());
490 static const coff_aux_section_definition
*findSectionDef(COFFObjectFile
*obj
,
492 uint32_t numSymbols
= obj
->getNumberOfSymbols();
493 for (uint32_t i
= 0; i
< numSymbols
; ++i
) {
494 COFFSymbolRef sym
= check(obj
->getSymbol(i
));
495 if (sym
.getSectionNumber() != section
)
497 if (const coff_aux_section_definition
*def
= sym
.getSectionDefinition())
503 void ObjFile::handleComdatSelection(
504 COFFSymbolRef sym
, COMDATType
&selection
, bool &prevailing
,
505 DefinedRegular
*leader
,
506 const llvm::object::coff_aux_section_definition
*def
) {
509 // There's already an existing comdat for this symbol: `Leader`.
510 // Use the comdats's selection field to determine if the new
511 // symbol in `Sym` should be discarded, produce a duplicate symbol
514 SectionChunk
*leaderChunk
= leader
->getChunk();
515 COMDATType leaderSelection
= leaderChunk
->selection
;
517 assert(leader
->data
&& "Comdat leader without SectionChunk?");
518 if (isa
<BitcodeFile
>(leader
->file
)) {
519 // If the leader is only a LTO symbol, we don't know e.g. its final size
520 // yet, so we can't do the full strict comdat selection checking yet.
521 selection
= leaderSelection
= IMAGE_COMDAT_SELECT_ANY
;
524 if ((selection
== IMAGE_COMDAT_SELECT_ANY
&&
525 leaderSelection
== IMAGE_COMDAT_SELECT_LARGEST
) ||
526 (selection
== IMAGE_COMDAT_SELECT_LARGEST
&&
527 leaderSelection
== IMAGE_COMDAT_SELECT_ANY
)) {
528 // cl.exe picks "any" for vftables when building with /GR- and
529 // "largest" when building with /GR. To be able to link object files
530 // compiled with each flag, "any" and "largest" are merged as "largest".
531 leaderSelection
= selection
= IMAGE_COMDAT_SELECT_LARGEST
;
534 // GCCs __declspec(selectany) doesn't actually pick "any" but "same size as".
535 // Clang on the other hand picks "any". To be able to link two object files
536 // with a __declspec(selectany) declaration, one compiled with gcc and the
537 // other with clang, we merge them as proper "same size as"
538 if (ctx
.config
.mingw
&& ((selection
== IMAGE_COMDAT_SELECT_ANY
&&
539 leaderSelection
== IMAGE_COMDAT_SELECT_SAME_SIZE
) ||
540 (selection
== IMAGE_COMDAT_SELECT_SAME_SIZE
&&
541 leaderSelection
== IMAGE_COMDAT_SELECT_ANY
))) {
542 leaderSelection
= selection
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
545 // Other than that, comdat selections must match. This is a bit more
546 // strict than link.exe which allows merging "any" and "largest" if "any"
547 // is the first symbol the linker sees, and it allows merging "largest"
548 // with everything (!) if "largest" is the first symbol the linker sees.
549 // Making this symmetric independent of which selection is seen first
550 // seems better though.
551 // (This behavior matches ModuleLinker::getComdatResult().)
552 if (selection
!= leaderSelection
) {
553 log(("conflicting comdat type for " + toString(ctx
, *leader
) + ": " +
554 Twine((int)leaderSelection
) + " in " + toString(leader
->getFile()) +
555 " and " + Twine((int)selection
) + " in " + toString(this))
557 ctx
.symtab
.reportDuplicate(leader
, this);
562 case IMAGE_COMDAT_SELECT_NODUPLICATES
:
563 ctx
.symtab
.reportDuplicate(leader
, this);
566 case IMAGE_COMDAT_SELECT_ANY
:
570 case IMAGE_COMDAT_SELECT_SAME_SIZE
:
571 if (leaderChunk
->getSize() != getSection(sym
)->SizeOfRawData
) {
572 if (!ctx
.config
.mingw
) {
573 ctx
.symtab
.reportDuplicate(leader
, this);
575 const coff_aux_section_definition
*leaderDef
= nullptr;
576 if (leaderChunk
->file
)
577 leaderDef
= findSectionDef(leaderChunk
->file
->getCOFFObj(),
578 leaderChunk
->getSectionNumber());
579 if (!leaderDef
|| leaderDef
->Length
!= def
->Length
)
580 ctx
.symtab
.reportDuplicate(leader
, this);
585 case IMAGE_COMDAT_SELECT_EXACT_MATCH
: {
586 SectionChunk
newChunk(this, getSection(sym
));
587 // link.exe only compares section contents here and doesn't complain
588 // if the two comdat sections have e.g. different alignment.
590 if (leaderChunk
->getContents() != newChunk
.getContents())
591 ctx
.symtab
.reportDuplicate(leader
, this, &newChunk
, sym
.getValue());
595 case IMAGE_COMDAT_SELECT_ASSOCIATIVE
:
596 // createDefined() is never called for IMAGE_COMDAT_SELECT_ASSOCIATIVE.
597 // (This means lld-link doesn't produce duplicate symbol errors for
598 // associative comdats while link.exe does, but associate comdats
599 // are never extern in practice.)
600 llvm_unreachable("createDefined not called for associative comdats");
602 case IMAGE_COMDAT_SELECT_LARGEST
:
603 if (leaderChunk
->getSize() < getSection(sym
)->SizeOfRawData
) {
604 // Replace the existing comdat symbol with the new one.
605 StringRef name
= check(coffObj
->getSymbolName(sym
));
606 // FIXME: This is incorrect: With /opt:noref, the previous sections
607 // make it into the final executable as well. Correct handling would
608 // be to undo reading of the whole old section that's being replaced,
609 // or doing one pass that determines what the final largest comdat
610 // is for all IMAGE_COMDAT_SELECT_LARGEST comdats and then reading
611 // only the largest one.
612 replaceSymbol
<DefinedRegular
>(leader
, this, name
, /*IsCOMDAT*/ true,
613 /*IsExternal*/ true, sym
.getGeneric(),
619 case IMAGE_COMDAT_SELECT_NEWEST
:
620 llvm_unreachable("should have been rejected earlier");
624 std::optional
<Symbol
*> ObjFile::createDefined(
626 std::vector
<const coff_aux_section_definition
*> &comdatDefs
,
629 auto getName
= [&]() { return check(coffObj
->getSymbolName(sym
)); };
631 if (sym
.isCommon()) {
632 auto *c
= make
<CommonChunk
>(sym
);
634 return ctx
.symtab
.addCommon(this, getName(), sym
.getValue(),
635 sym
.getGeneric(), c
);
638 if (sym
.isAbsolute()) {
639 StringRef name
= getName();
641 if (name
== "@feat.00")
642 feat00Flags
= sym
.getValue();
643 // Skip special symbols.
644 if (ignoredSymbolName(name
))
647 if (sym
.isExternal())
648 return ctx
.symtab
.addAbsolute(name
, sym
);
649 return make
<DefinedAbsolute
>(ctx
, name
, sym
);
652 int32_t sectionNumber
= sym
.getSectionNumber();
653 if (sectionNumber
== llvm::COFF::IMAGE_SYM_DEBUG
)
656 if (llvm::COFF::isReservedSectionNumber(sectionNumber
))
657 fatal(toString(this) + ": " + getName() +
658 " should not refer to special section " + Twine(sectionNumber
));
660 if ((uint32_t)sectionNumber
>= sparseChunks
.size())
661 fatal(toString(this) + ": " + getName() +
662 " should not refer to non-existent section " + Twine(sectionNumber
));
665 // A comdat symbol consists of two symbol table entries.
666 // The first symbol entry has the name of the section (e.g. .text), fixed
667 // values for the other fields, and one auxiliary record.
668 // The second symbol entry has the name of the comdat symbol, called the
670 // When this function is called for the first symbol entry of a comdat,
671 // it sets comdatDefs and returns std::nullopt, and when it's called for the
672 // second symbol entry it reads comdatDefs and then sets it back to nullptr.
674 // Handle comdat leader.
675 if (const coff_aux_section_definition
*def
= comdatDefs
[sectionNumber
]) {
676 comdatDefs
[sectionNumber
] = nullptr;
677 DefinedRegular
*leader
;
679 if (sym
.isExternal()) {
680 std::tie(leader
, prevailing
) =
681 ctx
.symtab
.addComdat(this, getName(), sym
.getGeneric());
683 leader
= make
<DefinedRegular
>(this, /*Name*/ "", /*IsCOMDAT*/ false,
684 /*IsExternal*/ false, sym
.getGeneric());
688 if (def
->Selection
< (int)IMAGE_COMDAT_SELECT_NODUPLICATES
||
689 // Intentionally ends at IMAGE_COMDAT_SELECT_LARGEST: link.exe
690 // doesn't understand IMAGE_COMDAT_SELECT_NEWEST either.
691 def
->Selection
> (int)IMAGE_COMDAT_SELECT_LARGEST
) {
692 fatal("unknown comdat type " + std::to_string((int)def
->Selection
) +
693 " for " + getName() + " in " + toString(this));
695 COMDATType selection
= (COMDATType
)def
->Selection
;
697 if (leader
->isCOMDAT
)
698 handleComdatSelection(sym
, selection
, prevailing
, leader
, def
);
701 SectionChunk
*c
= readSection(sectionNumber
, def
, getName());
702 sparseChunks
[sectionNumber
] = c
;
705 c
->sym
= cast
<DefinedRegular
>(leader
);
706 c
->selection
= selection
;
707 cast
<DefinedRegular
>(leader
)->data
= &c
->repl
;
709 sparseChunks
[sectionNumber
] = nullptr;
714 // Prepare to handle the comdat leader symbol by setting the section's
715 // ComdatDefs pointer if we encounter a non-associative comdat.
716 if (sparseChunks
[sectionNumber
] == pendingComdat
) {
717 if (const coff_aux_section_definition
*def
= sym
.getSectionDefinition()) {
718 if (def
->Selection
!= IMAGE_COMDAT_SELECT_ASSOCIATIVE
)
719 comdatDefs
[sectionNumber
] = def
;
724 return createRegular(sym
);
727 MachineTypes
ObjFile::getMachineType() {
729 return static_cast<MachineTypes
>(coffObj
->getMachine());
730 return IMAGE_FILE_MACHINE_UNKNOWN
;
733 ArrayRef
<uint8_t> ObjFile::getDebugSection(StringRef secName
) {
734 if (SectionChunk
*sec
= SectionChunk::findByName(debugChunks
, secName
))
735 return sec
->consumeDebugMagic();
739 // OBJ files systematically store critical information in a .debug$S stream,
740 // even if the TU was compiled with no debug info. At least two records are
741 // always there. S_OBJNAME stores a 32-bit signature, which is loaded into the
742 // PCHSignature member. S_COMPILE3 stores compile-time cmd-line flags. This is
743 // currently used to initialize the hotPatchable member.
744 void ObjFile::initializeFlags() {
745 ArrayRef
<uint8_t> data
= getDebugSection(".debug$S");
749 DebugSubsectionArray subsections
;
751 BinaryStreamReader
reader(data
, llvm::endianness::little
);
752 ExitOnError exitOnErr
;
753 exitOnErr(reader
.readArray(subsections
, data
.size()));
755 for (const DebugSubsectionRecord
&ss
: subsections
) {
756 if (ss
.kind() != DebugSubsectionKind::Symbols
)
761 // Only parse the first two records. We are only looking for S_OBJNAME
762 // and S_COMPILE3, and they usually appear at the beginning of the
764 for (unsigned i
= 0; i
< 2; ++i
) {
765 Expected
<CVSymbol
> sym
= readSymbolFromStream(ss
.getRecordData(), offset
);
767 consumeError(sym
.takeError());
770 if (sym
->kind() == SymbolKind::S_COMPILE3
) {
772 cantFail(SymbolDeserializer::deserializeAs
<Compile3Sym
>(sym
.get()));
774 (cs
.Flags
& CompileSym3Flags::HotPatch
) != CompileSym3Flags::None
;
776 if (sym
->kind() == SymbolKind::S_OBJNAME
) {
777 auto objName
= cantFail(SymbolDeserializer::deserializeAs
<ObjNameSym
>(
779 if (objName
.Signature
)
780 pchSignature
= objName
.Signature
;
782 offset
+= sym
->length();
787 // Depending on the compilation flags, OBJs can refer to external files,
788 // necessary to merge this OBJ into the final PDB. We currently support two
789 // types of external files: Precomp/PCH OBJs, when compiling with /Yc and /Yu.
790 // And PDB type servers, when compiling with /Zi. This function extracts these
791 // dependencies and makes them available as a TpiSource interface (see
792 // DebugTypes.h). Both cases only happen with cl.exe: clang-cl produces regular
793 // output even with /Yc and /Yu and with /Zi.
794 void ObjFile::initializeDependencies() {
795 if (!ctx
.config
.debug
)
800 ArrayRef
<uint8_t> data
= getDebugSection(".debug$P");
804 data
= getDebugSection(".debug$T");
806 // symbols but no types, make a plain, empty TpiSource anyway, because it
807 // simplifies adding the symbols later.
809 if (!debugChunks
.empty())
810 debugTypesObj
= makeTpiSource(ctx
, this);
814 // Get the first type record. It will indicate if this object uses a type
815 // server (/Zi) or a PCH file (/Yu).
817 BinaryStreamReader
reader(data
, llvm::endianness::little
);
818 cantFail(reader
.readArray(types
, reader
.getLength()));
819 CVTypeArray::Iterator firstType
= types
.begin();
820 if (firstType
== types
.end())
823 // Remember the .debug$T or .debug$P section.
826 // This object file is a PCH file that others will depend on.
828 debugTypesObj
= makePrecompSource(ctx
, this);
832 // This object file was compiled with /Zi. Enqueue the PDB dependency.
833 if (firstType
->kind() == LF_TYPESERVER2
) {
834 TypeServer2Record ts
= cantFail(
835 TypeDeserializer::deserializeAs
<TypeServer2Record
>(firstType
->data()));
836 debugTypesObj
= makeUseTypeServerSource(ctx
, this, ts
);
837 enqueuePdbFile(ts
.getName(), this);
841 // This object was compiled with /Yu. It uses types from another object file
842 // with a matching signature.
843 if (firstType
->kind() == LF_PRECOMP
) {
844 PrecompRecord precomp
= cantFail(
845 TypeDeserializer::deserializeAs
<PrecompRecord
>(firstType
->data()));
846 // We're better off trusting the LF_PRECOMP signature. In some cases the
847 // S_OBJNAME record doesn't contain a valid PCH signature.
848 if (precomp
.Signature
)
849 pchSignature
= precomp
.Signature
;
850 debugTypesObj
= makeUsePrecompSource(ctx
, this, precomp
);
851 // Drop the LF_PRECOMP record from the input stream.
852 debugTypes
= debugTypes
.drop_front(firstType
->RecordData
.size());
856 // This is a plain old object file.
857 debugTypesObj
= makeTpiSource(ctx
, this);
860 // The casing of the PDB path stamped in the OBJ can differ from the actual path
861 // on disk. With this, we ensure to always use lowercase as a key for the
862 // pdbInputFileInstances map, at least on Windows.
863 static std::string
normalizePdbPath(StringRef path
) {
867 return std::string(path
);
871 // If existing, return the actual PDB path on disk.
872 static std::optional
<std::string
>
873 findPdbPath(StringRef pdbPath
, ObjFile
*dependentFile
, StringRef outputPath
) {
874 // Ensure the file exists before anything else. In some cases, if the path
875 // points to a removable device, Driver::enqueuePath() would fail with an
876 // error (EAGAIN, "resource unavailable try again") which we want to skip
878 if (llvm::sys::fs::exists(pdbPath
))
879 return normalizePdbPath(pdbPath
);
881 StringRef objPath
= !dependentFile
->parentName
.empty()
882 ? dependentFile
->parentName
883 : dependentFile
->getName();
885 // Currently, type server PDBs are only created by MSVC cl, which only runs
886 // on Windows, so we can assume type server paths are Windows style.
887 StringRef pdbName
= sys::path::filename(pdbPath
, sys::path::Style::windows
);
889 // Check if the PDB is in the same folder as the OBJ.
890 SmallString
<128> path
;
891 sys::path::append(path
, sys::path::parent_path(objPath
), pdbName
);
892 if (llvm::sys::fs::exists(path
))
893 return normalizePdbPath(path
);
895 // Check if the PDB is in the output folder.
897 sys::path::append(path
, sys::path::parent_path(outputPath
), pdbName
);
898 if (llvm::sys::fs::exists(path
))
899 return normalizePdbPath(path
);
904 PDBInputFile::PDBInputFile(COFFLinkerContext
&ctx
, MemoryBufferRef m
)
905 : InputFile(ctx
, PDBKind
, m
) {}
907 PDBInputFile::~PDBInputFile() = default;
909 PDBInputFile
*PDBInputFile::findFromRecordPath(const COFFLinkerContext
&ctx
,
912 auto p
= findPdbPath(path
.str(), fromFile
, ctx
.config
.outputFile
);
915 auto it
= ctx
.pdbInputFileInstances
.find(*p
);
916 if (it
!= ctx
.pdbInputFileInstances
.end())
921 void PDBInputFile::parse() {
922 ctx
.pdbInputFileInstances
[mb
.getBufferIdentifier().str()] = this;
924 std::unique_ptr
<pdb::IPDBSession
> thisSession
;
925 Error E
= pdb::NativeSession::createFromPdb(
926 MemoryBuffer::getMemBuffer(mb
, false), thisSession
);
928 loadErrorStr
.emplace(toString(std::move(E
)));
929 return; // fail silently at this point - the error will be handled later,
930 // when merging the debug type stream
933 session
.reset(static_cast<pdb::NativeSession
*>(thisSession
.release()));
935 pdb::PDBFile
&pdbFile
= session
->getPDBFile();
936 auto expectedInfo
= pdbFile
.getPDBInfoStream();
937 // All PDB Files should have an Info stream.
939 loadErrorStr
.emplace(toString(expectedInfo
.takeError()));
942 debugTypesObj
= makeTypeServerSource(ctx
, this);
945 // Used only for DWARF debug info, which is not common (except in MinGW
946 // environments). This returns an optional pair of file name and line
947 // number for where the variable was defined.
948 std::optional
<std::pair
<StringRef
, uint32_t>>
949 ObjFile::getVariableLocation(StringRef var
) {
951 dwarf
= make
<DWARFCache
>(DWARFContext::create(*getCOFFObj()));
955 if (ctx
.config
.machine
== I386
)
956 var
.consume_front("_");
957 std::optional
<std::pair
<std::string
, unsigned>> ret
=
958 dwarf
->getVariableLoc(var
);
961 return std::make_pair(saver().save(ret
->first
), ret
->second
);
964 // Used only for DWARF debug info, which is not common (except in MinGW
966 std::optional
<DILineInfo
> ObjFile::getDILineInfo(uint32_t offset
,
967 uint32_t sectionIndex
) {
969 dwarf
= make
<DWARFCache
>(DWARFContext::create(*getCOFFObj()));
974 return dwarf
->getDILineInfo(offset
, sectionIndex
);
977 void ObjFile::enqueuePdbFile(StringRef path
, ObjFile
*fromFile
) {
978 auto p
= findPdbPath(path
.str(), fromFile
, ctx
.config
.outputFile
);
981 auto it
= ctx
.pdbInputFileInstances
.emplace(*p
, nullptr);
983 return; // already scheduled for load
984 ctx
.driver
.enqueuePDB(*p
);
987 ImportFile::ImportFile(COFFLinkerContext
&ctx
, MemoryBufferRef m
)
988 : InputFile(ctx
, ImportKind
, m
), live(!ctx
.config
.doGC
), thunkLive(live
) {}
990 void ImportFile::parse() {
992 reinterpret_cast<const coff_import_header
*>(mb
.getBufferStart());
994 // Check if the total size is valid.
995 if (mb
.getBufferSize() < sizeof(*hdr
) ||
996 mb
.getBufferSize() != sizeof(*hdr
) + hdr
->SizeOfData
)
997 fatal("broken import library");
999 // Read names and create an __imp_ symbol.
1000 StringRef buf
= mb
.getBuffer().substr(sizeof(*hdr
));
1001 StringRef name
= saver().save(buf
.split('\0').first
);
1002 StringRef impName
= saver().save("__imp_" + name
);
1003 buf
= buf
.substr(name
.size() + 1);
1004 dllName
= buf
.split('\0').first
;
1006 switch (hdr
->getNameType()) {
1007 case IMPORT_ORDINAL
:
1013 case IMPORT_NAME_NOPREFIX
:
1014 extName
= ltrim1(name
, "?@_");
1016 case IMPORT_NAME_UNDECORATE
:
1017 extName
= ltrim1(name
, "?@_");
1018 extName
= extName
.substr(0, extName
.find('@'));
1020 case IMPORT_NAME_EXPORTAS
:
1021 extName
= buf
.substr(dllName
.size() + 1).split('\0').first
;
1026 externalName
= extName
;
1028 impSym
= ctx
.symtab
.addImportData(impName
, this);
1029 // If this was a duplicate, we logged an error but may continue;
1030 // in this case, impSym is nullptr.
1034 if (hdr
->getType() == llvm::COFF::IMPORT_CONST
)
1035 static_cast<void>(ctx
.symtab
.addImportData(name
, this));
1037 // If type is function, we need to create a thunk which jump to an
1038 // address pointed by the __imp_ symbol. (This allows you to call
1039 // DLL functions just like regular non-DLL functions.)
1040 if (hdr
->getType() == llvm::COFF::IMPORT_CODE
)
1041 thunkSym
= ctx
.symtab
.addImportThunk(
1042 name
, cast_or_null
<DefinedImportData
>(impSym
), hdr
->Machine
);
1045 BitcodeFile::BitcodeFile(COFFLinkerContext
&ctx
, MemoryBufferRef mb
,
1046 StringRef archiveName
, uint64_t offsetInArchive
,
1048 : InputFile(ctx
, BitcodeKind
, mb
, lazy
) {
1049 std::string path
= mb
.getBufferIdentifier().str();
1050 if (ctx
.config
.thinLTOIndexOnly
)
1051 path
= replaceThinLTOSuffix(mb
.getBufferIdentifier(),
1052 ctx
.config
.thinLTOObjectSuffixReplace
.first
,
1053 ctx
.config
.thinLTOObjectSuffixReplace
.second
);
1055 // ThinLTO assumes that all MemoryBufferRefs given to it have a unique
1056 // name. If two archives define two members with the same name, this
1057 // causes a collision which result in only one of the objects being taken
1058 // into consideration at LTO time (which very likely causes undefined
1059 // symbols later in the link stage). So we append file offset to make
1061 MemoryBufferRef
mbref(mb
.getBuffer(),
1062 saver().save(archiveName
.empty()
1065 sys::path::filename(path
) +
1066 utostr(offsetInArchive
)));
1068 obj
= check(lto::InputFile::create(mbref
));
1071 BitcodeFile::~BitcodeFile() = default;
1073 void BitcodeFile::parse() {
1074 llvm::StringSaver
&saver
= lld::saver();
1076 std::vector
<std::pair
<Symbol
*, bool>> comdat(obj
->getComdatTable().size());
1077 for (size_t i
= 0; i
!= obj
->getComdatTable().size(); ++i
)
1078 // FIXME: Check nodeduplicate
1080 ctx
.symtab
.addComdat(this, saver
.save(obj
->getComdatTable()[i
].first
));
1081 for (const lto::InputFile::Symbol
&objSym
: obj
->symbols()) {
1082 StringRef symName
= saver
.save(objSym
.getName());
1083 int comdatIndex
= objSym
.getComdatIndex();
1085 SectionChunk
*fakeSC
= nullptr;
1086 if (objSym
.isExecutable())
1087 fakeSC
= &ctx
.ltoTextSectionChunk
.chunk
;
1089 fakeSC
= &ctx
.ltoDataSectionChunk
.chunk
;
1090 if (objSym
.isUndefined()) {
1091 sym
= ctx
.symtab
.addUndefined(symName
, this, false);
1092 if (objSym
.isWeak())
1093 sym
->deferUndefined
= true;
1094 // If one LTO object file references (i.e. has an undefined reference to)
1095 // a symbol with an __imp_ prefix, the LTO compilation itself sees it
1096 // as unprefixed but with a dllimport attribute instead, and doesn't
1097 // understand the relation to a concrete IR symbol with the __imp_ prefix.
1099 // For such cases, mark the symbol as used in a regular object (i.e. the
1100 // symbol must be retained) so that the linker can associate the
1101 // references in the end. If the symbol is defined in an import library
1102 // or in a regular object file, this has no effect, but if it is defined
1103 // in another LTO object file, this makes sure it is kept, to fulfill
1104 // the reference when linking the output of the LTO compilation.
1105 if (symName
.starts_with("__imp_"))
1106 sym
->isUsedInRegularObj
= true;
1107 } else if (objSym
.isCommon()) {
1108 sym
= ctx
.symtab
.addCommon(this, symName
, objSym
.getCommonSize());
1109 } else if (objSym
.isWeak() && objSym
.isIndirect()) {
1111 sym
= ctx
.symtab
.addUndefined(symName
, this, true);
1112 std::string fallback
= std::string(objSym
.getCOFFWeakExternalFallback());
1113 Symbol
*alias
= ctx
.symtab
.addUndefined(saver
.save(fallback
));
1114 checkAndSetWeakAlias(ctx
, this, sym
, alias
);
1115 } else if (comdatIndex
!= -1) {
1116 if (symName
== obj
->getComdatTable()[comdatIndex
].first
) {
1117 sym
= comdat
[comdatIndex
].first
;
1118 if (cast
<DefinedRegular
>(sym
)->data
== nullptr)
1119 cast
<DefinedRegular
>(sym
)->data
= &fakeSC
->repl
;
1120 } else if (comdat
[comdatIndex
].second
) {
1121 sym
= ctx
.symtab
.addRegular(this, symName
, nullptr, fakeSC
);
1123 sym
= ctx
.symtab
.addUndefined(symName
, this, false);
1126 sym
= ctx
.symtab
.addRegular(this, symName
, nullptr, fakeSC
, 0,
1129 symbols
.push_back(sym
);
1130 if (objSym
.isUsed())
1131 ctx
.config
.gcroot
.push_back(sym
);
1133 directives
= saver
.save(obj
->getCOFFLinkerOpts());
1136 void BitcodeFile::parseLazy() {
1137 for (const lto::InputFile::Symbol
&sym
: obj
->symbols())
1138 if (!sym
.isUndefined())
1139 ctx
.symtab
.addLazyObject(this, sym
.getName());
1142 MachineTypes
BitcodeFile::getMachineType() {
1143 switch (Triple(obj
->getTargetTriple()).getArch()) {
1144 case Triple::x86_64
:
1151 case Triple::aarch64
:
1154 return IMAGE_FILE_MACHINE_UNKNOWN
;
1158 std::string
lld::coff::replaceThinLTOSuffix(StringRef path
, StringRef suffix
,
1160 if (path
.consume_back(suffix
))
1161 return (path
+ repl
).str();
1162 return std::string(path
);
1165 static bool isRVACode(COFFObjectFile
*coffObj
, uint64_t rva
, InputFile
*file
) {
1166 for (size_t i
= 1, e
= coffObj
->getNumberOfSections(); i
<= e
; i
++) {
1167 const coff_section
*sec
= CHECK(coffObj
->getSection(i
), file
);
1168 if (rva
>= sec
->VirtualAddress
&&
1169 rva
<= sec
->VirtualAddress
+ sec
->VirtualSize
) {
1170 return (sec
->Characteristics
& COFF::IMAGE_SCN_CNT_CODE
) != 0;
1176 void DLLFile::parse() {
1177 // Parse a memory buffer as a PE-COFF executable.
1178 std::unique_ptr
<Binary
> bin
= CHECK(createBinary(mb
), this);
1180 if (auto *obj
= dyn_cast
<COFFObjectFile
>(bin
.get())) {
1184 error(toString(this) + " is not a COFF file");
1188 if (!coffObj
->getPE32Header() && !coffObj
->getPE32PlusHeader()) {
1189 error(toString(this) + " is not a PE-COFF executable");
1193 for (const auto &exp
: coffObj
->export_directories()) {
1194 StringRef dllName
, symbolName
;
1196 checkError(exp
.getDllName(dllName
));
1197 checkError(exp
.getSymbolName(symbolName
));
1198 checkError(exp
.getExportRVA(exportRVA
));
1200 if (symbolName
.empty())
1203 bool code
= isRVACode(coffObj
.get(), exportRVA
, this);
1205 Symbol
*s
= make
<Symbol
>();
1206 s
->dllName
= dllName
;
1207 s
->symbolName
= symbolName
;
1208 s
->importType
= code
? ImportType::IMPORT_CODE
: ImportType::IMPORT_DATA
;
1209 s
->nameType
= ImportNameType::IMPORT_NAME
;
1211 if (coffObj
->getMachine() == I386
) {
1212 s
->symbolName
= symbolName
= saver().save("_" + symbolName
);
1213 s
->nameType
= ImportNameType::IMPORT_NAME_NOPREFIX
;
1216 StringRef impName
= saver().save("__imp_" + symbolName
);
1217 ctx
.symtab
.addLazyDLLSymbol(this, s
, impName
);
1219 ctx
.symtab
.addLazyDLLSymbol(this, s
, symbolName
);
1223 MachineTypes
DLLFile::getMachineType() {
1225 return static_cast<MachineTypes
>(coffObj
->getMachine());
1226 return IMAGE_FILE_MACHINE_UNKNOWN
;
1229 void DLLFile::makeImport(DLLFile::Symbol
*s
) {
1230 if (!seen
.insert(s
->symbolName
).second
)
1233 size_t impSize
= s
->dllName
.size() + s
->symbolName
.size() + 2; // +2 for NULs
1234 size_t size
= sizeof(coff_import_header
) + impSize
;
1235 char *buf
= bAlloc().Allocate
<char>(size
);
1236 memset(buf
, 0, size
);
1238 auto *imp
= reinterpret_cast<coff_import_header
*>(p
);
1241 imp
->Machine
= coffObj
->getMachine();
1242 imp
->SizeOfData
= impSize
;
1243 imp
->OrdinalHint
= 0; // Only linking by name
1244 imp
->TypeInfo
= (s
->nameType
<< 2) | s
->importType
;
1246 // Write symbol name and DLL name.
1247 memcpy(p
, s
->symbolName
.data(), s
->symbolName
.size());
1248 p
+= s
->symbolName
.size() + 1;
1249 memcpy(p
, s
->dllName
.data(), s
->dllName
.size());
1250 MemoryBufferRef mbref
= MemoryBufferRef(StringRef(buf
, size
), s
->dllName
);
1251 ImportFile
*impFile
= make
<ImportFile
>(ctx
, mbref
);
1252 ctx
.symtab
.addFile(impFile
);