@@ -359,7 +359,15 @@ void WasmObjectWriter::startCustomSection(SectionBookkeeping &Section,
359
359
Section.PayloadOffset = W.OS .tell ();
360
360
361
361
// Custom sections in wasm also have a string identifier.
362
- writeString (Name);
362
+ if (Name != " __clangast" ) {
363
+ writeString (Name);
364
+ } else {
365
+ // pad section start to nearest 4 bytes for Clang PCH
366
+ uint64_t MinLength = Section.PayloadOffset + 5ULL /* min ULEB128 length */ + Name.size ();
367
+ uint64_t RoundedUpLength = (MinLength + 3ULL ) & ~3ULL ;
368
+ encodeULEB128 (Name.size (), W.OS , 5 + (RoundedUpLength - MinLength));
369
+ W.OS << Name;
370
+ }
363
371
364
372
// The position where the custom section starts.
365
373
Section.ContentsOffset = W.OS .tell ();
@@ -1052,6 +1060,14 @@ void WasmObjectWriter::writeCustomSections(const MCAssembler &Asm,
1052
1060
auto *Sec = CustomSection.Section ;
1053
1061
startCustomSection (Section, CustomSection.Name );
1054
1062
1063
+ if (CustomSection.Name == " __clangast" ) {
1064
+ // pad to nearest 4 bytes
1065
+ uint64_t RoundedUp = (Section.ContentsOffset + 3ULL ) & ~3ULL ;
1066
+ for (uint64_t Count = 0 ; Count < RoundedUp - Section.ContentsOffset ; Count++) {
1067
+ W.OS << char (0 );
1068
+ }
1069
+ }
1070
+
1055
1071
Sec->setSectionOffset (W.OS .tell () - Section.ContentsOffset );
1056
1072
Asm.writeSectionData (W.OS , Sec, Layout);
1057
1073
@@ -1342,6 +1358,8 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm,
1342
1358
LLVM_DEBUG (dbgs () << " -> function index: " << Index << " \n " );
1343
1359
1344
1360
} else if (WS.isData ()) {
1361
+ if (WS.getName () == " __clang_ast" )
1362
+ continue ;
1345
1363
if (WS.isTemporary () && !WS.getSize ())
1346
1364
continue ;
1347
1365
0 commit comments