20
20
#include " lld/Common/Strings.h"
21
21
#include " lld/Common/Threads.h"
22
22
#include " llvm/ADT/DenseSet.h"
23
+ #include " llvm/ADT/StringMap.h"
23
24
#include " llvm/BinaryFormat/Wasm.h"
24
25
#include " llvm/Object/WasmTraits.h"
25
26
#include " llvm/Support/FileOutputBuffer.h"
@@ -85,6 +86,7 @@ class Writer {
85
86
void createElemSection ();
86
87
void createCodeSection ();
87
88
void createDataSection ();
89
+ void createCustomSections ();
88
90
89
91
// Custom sections
90
92
void createRelocSections ();
@@ -111,6 +113,8 @@ class Writer {
111
113
std::vector<const Symbol *> SymtabEntries;
112
114
std::vector<WasmInitEntry> InitFunctions;
113
115
116
+ llvm::StringMap<std::vector<InputSection *>> CustomSectionMapping;
117
+
114
118
// Elements that are used to construct the final output
115
119
std::string Header;
116
120
std::vector<OutputSection *> OutputSections;
@@ -295,6 +299,23 @@ void Writer::createExportSection() {
295
299
}
296
300
}
297
301
302
+ void Writer::createCustomSections () {
303
+ log (" createCustomSections" );
304
+ for (ObjFile *File : Symtab->ObjectFiles )
305
+ for (InputSection *Section : File->CustomSections )
306
+ CustomSectionMapping[Section->getName ()].push_back (Section);
307
+
308
+ for (auto &Pair : CustomSectionMapping) {
309
+ StringRef Name = Pair.first ();
310
+ // These custom sections are known the linker and synthesized rather than
311
+ // blindly copied
312
+ if (Name == " linking" || Name == " name" || Name.startswith (" reloc." ))
313
+ continue ;
314
+ DEBUG (dbgs () << " createCustomSection: " << Name << " \n " );
315
+ OutputSections.push_back (make<CustomSection>(Name, Pair.second ));
316
+ }
317
+ }
318
+
298
319
void Writer::createElemSection () {
299
320
if (IndirectFunctions.empty ())
300
321
return ;
@@ -647,6 +668,7 @@ void Writer::createSections() {
647
668
createElemSection ();
648
669
createCodeSection ();
649
670
createDataSection ();
671
+ createCustomSections ();
650
672
651
673
// Custom sections
652
674
if (Config->Relocatable ) {
0 commit comments