diff options
author | Sam Clegg <sbc@chromium.org> | 2024-08-19 21:52:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-19 21:52:17 -0700 |
commit | 2a6136e552d24b6bf665c42a6e32efc0b2d88fbf (patch) | |
tree | b7d9248a47553484ea96fd958bd0cbc7482f385b /llvm/lib/ObjCopy/wasm/WasmObject.cpp | |
parent | 5403123197f8e331d3c2c24d82439ca1fe7e702d (diff) | |
download | llvm-upstream/main.zip llvm-upstream/main.tar.gz llvm-upstream/main.tar.bz2 |
[llvm-objcopy][WebAssembly] Allow --strip-debug to operate on relocatable files. (#102978)upstream/main
This change is enough to allow `--strip-debug` to work on object files,
without breaking the relocation information or symbol table.
A more complete version of this change would instead reconstruct the
symbol table and relocation sections, but that is much larger change.
Bug: #102002
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 |