[Lldb-commits] [PATCH] D127164: [WebAssembly] Add WASM_SEC_LAST_KNOWN to BinaryFormat section types list [NFC]
Derek Schuff via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 6 15:46:33 PDT 2022
dschuff created this revision.
dschuff added reviewers: aheejin, sbc100.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, hiraditya, jgravelle-google.
Herald added a reviewer: jhenderson.
Herald added a project: All.
dschuff requested review of this revision.
Herald added subscribers: llvm-commits, lldb-commits, MaskRay.
Herald added projects: LLDB, LLVM.
There are 3 places where we were using WASM_SEC_TAG as the "last" known
section type, which requires updating (or leaves a bug) when a new known
section type is added. Instead add a "last type" to the enum for this
purpose.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127164
Files:
lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
llvm/include/llvm/BinaryFormat/Wasm.h
llvm/lib/ObjCopy/wasm/WasmReader.cpp
llvm/lib/Object/WasmObjectFile.cpp
Index: llvm/lib/Object/WasmObjectFile.cpp
===================================================================
--- llvm/lib/Object/WasmObjectFile.cpp
+++ llvm/lib/Object/WasmObjectFile.cpp
@@ -1729,7 +1729,7 @@
const WasmSection &S = Sections[Sec.d.a];
if (S.Type == wasm::WASM_SEC_CUSTOM)
return S.Name;
- if (S.Type > wasm::WASM_SEC_TAG)
+ if (S.Type >= wasm::WASM_SEC_LAST_KNOWN)
return createStringError(object_error::invalid_section_index, "");
return wasm::sectionTypeToString(S.Type);
}
Index: llvm/lib/ObjCopy/wasm/WasmReader.cpp
===================================================================
--- llvm/lib/ObjCopy/wasm/WasmReader.cpp
+++ llvm/lib/ObjCopy/wasm/WasmReader.cpp
@@ -27,12 +27,8 @@
// Give known sections standard names to allow them to be selected.
Section &ReaderSec = Obj->Sections.back();
if (ReaderSec.SectionType > WASM_SEC_CUSTOM &&
- ReaderSec.SectionType <= WASM_SEC_TAG)
+ ReaderSec.SectionType < WASM_SEC_LAST_KNOWN)
ReaderSec.Name = sectionTypeToString(ReaderSec.SectionType);
- // If the section type is CUSTOM, it has a name already. If it's a new type
- // of section that we don't explicitly handle here, it will have an empty
- // name and objcopy won't be able to select it by name (e.g. for removal
- // or dumping) but it will still be valid and able to be copied.
}
return std::move(Obj);
}
Index: llvm/include/llvm/BinaryFormat/Wasm.h
===================================================================
--- llvm/include/llvm/BinaryFormat/Wasm.h
+++ llvm/include/llvm/BinaryFormat/Wasm.h
@@ -252,7 +252,8 @@
WASM_SEC_CODE = 10, // Function bodies (code)
WASM_SEC_DATA = 11, // Data segments
WASM_SEC_DATACOUNT = 12, // Data segment count
- WASM_SEC_TAG = 13 // Tag declarations
+ WASM_SEC_TAG = 13, // Tag declarations
+ WASM_SEC_LAST_KNOWN = 14,// Update this when adding new sections
};
// Type immediate encodings used in various contexts.
Index: lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
+++ lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
@@ -192,7 +192,7 @@
m_sect_infos.push_back(section_info{*offset_ptr + c.tell(), section_length,
section_id, *sect_name});
*offset_ptr += (c.tell() + section_length);
- } else if (section_id <= llvm::wasm::WASM_SEC_TAG) {
+ } else if (section_id < llvm::wasm::WASM_SEC_LAST_KNOWN) {
m_sect_infos.push_back(section_info{*offset_ptr + c.tell(),
static_cast<uint32_t>(payload_len),
section_id, ConstString()});
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127164.434636.patch
Type: text/x-patch
Size: 2799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220606/84899fe5/attachment.bin>
More information about the lldb-commits
mailing list