46 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "WasmObject.h"10 11namespace llvm {12namespace objcopy {13namespace wasm {14 15using namespace object;16using namespace llvm::wasm;17 18void Object::addSectionWithOwnedContents(19 Section NewSection, std::unique_ptr<MemoryBuffer> &&Content) {20 Sections.push_back(NewSection);21 OwnedContents.emplace_back(std::move(Content));22}23 24void 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 and29 // 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;36 }37 }38 } else {39 llvm::erase_if(Sections, ToRemove);40 }41}42 43} // end namespace wasm44} // end namespace objcopy45} // end namespace llvm46