LLVM 20.0.0git
WasmObject.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
9#include "WasmObject.h"
10
11namespace llvm {
12namespace objcopy {
13namespace wasm {
14
15using namespace object;
16using namespace llvm::wasm;
17
19 Section NewSection, std::unique_ptr<MemoryBuffer> &&Content) {
20 Sections.push_back(NewSection);
21 OwnedContents.emplace_back(std::move(Content));
22}
23
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;
36 }
37 }
38 } else {
40 }
41}
42
43} // end namespace wasm
44} // end namespace objcopy
45} // end namespace llvm
ReachingDefAnalysis InstSet & ToRemove
T Content
An efficient, type-erasing, non-owning reference to a callable.
@ WASM_SEC_CUSTOM
Definition: Wasm.h:35
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition: STLExtras.h:2099
std::vector< Section > Sections
Definition: WasmObject.h:34
void addSectionWithOwnedContents(Section NewSection, std::unique_ptr< MemoryBuffer > &&Content)
Definition: WasmObject.cpp:18
void removeSections(function_ref< bool(const Section &)> ToRemove)
Definition: WasmObject.cpp:24