[llvm] [llvm-objcopy][COFF] Update WinCFGuard section contents after stripping (PR #153322)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 22 02:39:21 PDT 2025
================
@@ -92,6 +94,76 @@ Error COFFWriter::finalizeSymbolContents() {
return Error::success();
}
+Error COFFWriter::finalizeSymIdxContents() {
+ // CFGuards shouldn't be present in PE.
+ if (Obj.IsPE)
+ return Error::success();
+
+ // Currently handle only sections consisting only of .symidx.
+ // TODO: other sections such as .impcall and .hybmp$x require more complex
+ // handling as they have more complex layout.
+ auto IsSymIdxSection = [](StringRef Name) {
+ return Name == ".gljmp$y" || Name == ".giats$y" || Name == ".gfids$y" ||
+ Name == ".gehcont$y";
+ };
+
+ DenseMap<size_t, size_t> SymIdMap;
+ SmallDenseMap<ssize_t, coff_aux_section_definition *, 4> SecIdMap;
+ for (Symbol &Sym : Obj.getMutableSymbols()) {
+ SymIdMap[Sym.OriginalRawIndex] = Sym.RawIndex;
+
+ // We collect only definition symbols of the sections to update checksum.
+ if (Sym.Sym.StorageClass == IMAGE_SYM_CLASS_STATIC &&
+ Sym.Sym.NumberOfAuxSymbols == 1 && Sym.Sym.Value == 0 &&
+ IsSymIdxSection(Sym.Name))
+ SecIdMap[Sym.TargetSectionId] =
+ reinterpret_cast<coff_aux_section_definition *>(
+ Sym.AuxData[0].Opaque);
+ }
+
+ for (Section &Sec : Obj.getMutableSections()) {
+ if (!IsSymIdxSection(Sec.Name))
+ continue;
+
+ ArrayRef<uint8_t> RawIds = Sec.getContents();
+ // Nothing to do and also CheckSum will be -1 instead of 0 if we recalculate
----------------
jh7370 wrote:
Same comment as above.
https://github.com/llvm/llvm-project/pull/153322
More information about the llvm-commits
mailing list