LLVM: lib/ObjCopy/wasm/WasmObjcopy.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
16
17namespace llvm {
18namespace objcopy {
19namespace wasm {
20
21using namespace object;
23
26}
27
30}
31
33
34
35
37 return Sec.Name == "producers";
38}
39
43 if (Sec.Name == SecName) {
47 if (!BufferOrErr)
49 std::unique_ptr Buf = std::move(*BufferOrErr);
50 std::copy(Contents.begin(), Contents.end(), Buf->getBufferStart());
51 if (Error E = Buf->commit())
52 return E;
54 }
55 }
57 SecName.str().c_str());
58}
59
62
63
64 if (.ToRemove.empty()) {
66 return Config.ToRemove.matches(Sec.Name);
67 };
68 }
69
70 if (Config.StripDebug) {
71 RemovePred = [RemovePred](const Section &Sec) {
73 };
74 }
75
76 if (Config.StripAll) {
77 RemovePred = [RemovePred](const Section &Sec) {
80 };
81 }
82
83 if (Config.OnlyKeepDebug) {
85
86
88 };
89 }
90
91 if (.OnlySection.empty()) {
93
94
95 return .OnlySection.matches(Sec.Name);
96 };
97 }
98
99 if (.KeepSection.empty()) {
100 RemovePred = [&Config, RemovePred](const Section &Sec) {
101
102 if (Config.KeepSection.matches(Sec.Name))
103 return false;
104
105 return RemovePred(Sec);
106 };
107 }
108
110}
111
113
117 std::tie(SecName, FileName) = Flag.split("=");
120 }
121
123
128
131 NewSection.SectionData->getBufferSize());
133 InputData, NewSection.SectionData->getBufferIdentifier());
135 reinterpret_cast<const uint8_t *>(BufferCopy->getBufferStart()),
136 BufferCopy->getBufferSize());
137
139 }
140
142}
143
146 Reader TheReader(In);
148 if (!ObjOrErr)
151 assert(Obj && "Unable to deserialize Wasm object");
153 return E;
154 Writer TheWriter(*Obj, Out);
158}
159
160}
161}
162}
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
static Expected< std::unique_ptr< FileOutputBuffer > > create(StringRef FilePath, size_t Size, unsigned Flags=0)
Factory method to create an OutputBuffer object which manages a read/write buffer of the specified si...
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Expected< std::unique_ptr< Object > > create() const
This class implements an extremely fast bulk output stream that can only output to a stream.
static bool isCommentSection(const Section &Sec)
static void removeSections(const CommonConfig &Config, Object &Obj)
static Error dumpSectionToFile(StringRef SecName, StringRef Filename, Object &Obj)
static Error handleArgs(const CommonConfig &Config, Object &Obj)
static bool isDebugSection(const Section &Sec)
std::function< bool(const Section &Sec)> SectionPred
static bool isNameSection(const Section &Sec)
static bool isLinkerSection(const Section &Sec)
Error executeObjcopyOnBinary(const CommonConfig &Config, const WasmConfig &, object::WasmObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and WasmConfig to In and writes the result into Out.
This is an optimization pass for GlobalISel generic memory operations.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
std::shared_ptr< MemoryBuffer > SectionData
std::vector< Section > Sections
void addSectionWithOwnedContents(Section NewSection, std::unique_ptr< MemoryBuffer > &&Content)
void removeSections(function_ref< bool(const Section &)> ToRemove)
ArrayRef< uint8_t > Contents