[lld][WebAssembly] Introduce Ctx::arg
[llvm-project.git] / llvm / lib / ObjCopy / wasm / WasmObject.cpp
blob991191320c40b82898af2e0388f111788b0feaeb
1 //===- WasmObject.cpp -----------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "WasmObject.h"
11 namespace llvm {
12 namespace objcopy {
13 namespace wasm {
15 using namespace object;
16 using namespace llvm::wasm;
18 void Object::addSectionWithOwnedContents(
19 Section NewSection, std::unique_ptr<MemoryBuffer> &&Content) {
20 Sections.push_back(NewSection);
21 OwnedContents.emplace_back(std::move(Content));
24 void Object::removeSections(function_ref<bool(const Section &)> ToRemove) {
25 if (isRelocatableObject) {
26 // For relocatable objects, avoid actually removing any sections,
27 // since that can invalidate the symbol table and relocation sections.
28 // TODO: Allow removal of sections by re-generating symbol table and
29 // relocation sections here instead.
30 for (auto &Sec : Sections) {
31 if (ToRemove(Sec)) {
32 Sec.Name = ".objcopy.removed";
33 Sec.SectionType = wasm::WASM_SEC_CUSTOM;
34 Sec.Contents = {};
35 Sec.HeaderSecSizeEncodingLen = std::nullopt;
38 } else {
39 llvm::erase_if(Sections, ToRemove);
43 } // end namespace wasm
44 } // end namespace objcopy
45 } // end namespace llvm