1 //===- WasmObject.cpp -----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "WasmObject.h"
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
) {
32 Sec
.Name
= ".objcopy.removed";
33 Sec
.SectionType
= wasm::WASM_SEC_CUSTOM
;
35 Sec
.HeaderSecSizeEncodingLen
= std::nullopt
;
39 llvm::erase_if(Sections
, ToRemove
);
43 } // end namespace wasm
44 } // end namespace objcopy
45 } // end namespace llvm