[llvm] [ELF][Objcopy] Dont corrupt symbol table when `--update-section` is called for ELF files (PR #170462)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 08:21:35 PST 2025
================
@@ -2171,7 +2171,14 @@ Error Object::updateSectionData(SecPtr &Sec, ArrayRef<uint8_t> Data) {
Data.size(), Sec->Name.c_str(), Sec->Size);
if (!Sec->ParentSegment) {
- Sec = std::make_unique<OwnedDataSection>(*Sec, Data);
+ // Be careful: the "Sec" refers to an item in a std::vector,
+ // so any changes to the std::vector could invalidate this reference.
+ // To avoid possible memory-related issues, save raw pointers.
+ auto Replaced = Sec.get();
+ auto Modified = &addSection<OwnedDataSection>(*Sec, Data);
----------------
jh7370 wrote:
If I'm not mistaken, won't this end up with a section containing the new contents as well as a section with the old contents in the object?
https://github.com/llvm/llvm-project/pull/170462
More information about the llvm-commits
mailing list