diff options
Diffstat (limited to 'llvm/lib/ObjCopy/wasm/WasmObject.cpp')
-rw-r--r-- | llvm/lib/ObjCopy/wasm/WasmObject.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/ObjCopy/wasm/WasmObject.cpp b/llvm/lib/ObjCopy/wasm/WasmObject.cpp index 28a2de6..0b543b7 100644 --- a/llvm/lib/ObjCopy/wasm/WasmObject.cpp +++ b/llvm/lib/ObjCopy/wasm/WasmObject.cpp @@ -25,8 +25,22 @@ void Object::addSectionWithOwnedContents( } void Object::removeSections(function_ref<bool(const Section &)> ToRemove) { - // TODO: remove reloc sections for the removed section, handle symbols, etc. - llvm::erase_if(Sections, ToRemove); + if (isRelocatableObject) { + // For relocatable objects, avoid actually removing any sections, + // since that can invalidate the symbol table and relocation sections. + // TODO: Allow removal of sections by re-generating symbol table and + // relocation sections here instead. + for (auto &Sec : Sections) { + if (ToRemove(Sec)) { + Sec.Name = ".objcopy.removed"; + Sec.SectionType = wasm::WASM_SEC_CUSTOM; + Sec.Contents = {}; + Sec.HeaderSecSizeEncodingLen = std::nullopt; + } + } + } else { + llvm::erase_if(Sections, ToRemove); + } } } // end namespace wasm |