[llvm] [llvm-objcopy][ELF] Add an option to remove notes (PR #118739)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 01:00:42 PST 2025
================
@@ -609,6 +609,97 @@ static void addSymbol(Object &Obj, const NewSymbolInfo &SymInfo,
Sec ? (uint16_t)SYMBOL_SIMPLE_INDEX : (uint16_t)SHN_ABS, 0);
}
+namespace {
+struct RemoveNoteDetail {
+ struct DeletedRange {
+ uint64_t OldFrom;
+ uint64_t OldTo;
+ uint64_t NewPos;
+ };
+
+ template <class ELFT>
+ static std::vector<DeletedRange>
+ findNotesToRemove(ArrayRef<uint8_t> Data, size_t Align,
+ ArrayRef<RemoveNoteInfo> NotesToRemove);
+ static std::vector<uint8_t> updateData(ArrayRef<uint8_t> OldData,
+ ArrayRef<DeletedRange> ToRemove);
+};
+
+} // namespace
+
+template <class ELFT>
+std::vector<RemoveNoteDetail::DeletedRange>
+RemoveNoteDetail::findNotesToRemove(ArrayRef<uint8_t> Data, size_t Align,
+ ArrayRef<RemoveNoteInfo> NotesToRemove) {
+ LLVM_ELF_IMPORT_TYPES_ELFT(ELFT);
+ std::vector<DeletedRange> ToRemove;
+ uint64_t CurPos = 0;
+ uint64_t NewPos = 0;
+ while (CurPos + sizeof(Elf_Nhdr) <= Data.size()) {
+ auto Nhdr = reinterpret_cast<const Elf_Nhdr *>(Data.data() + CurPos);
----------------
jh7370 wrote:
Do we need to worry about misaligned note sections? I.e. where the file position isn't aligned correctly. Could that cause problems trying to read the note fields on some architectures?
https://github.com/llvm/llvm-project/pull/118739
More information about the llvm-commits
mailing list