[PATCH] D120645: [Object] Skip section offset checking for /<XFGHASHMAP>/
Pavel Samolysov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 1 01:10:33 PST 2022
psamolysov-intel updated this revision to Diff 412000.
psamolysov-intel added a comment.
Thank you for the suggestion. I've added a python script to replace a section with /<XFGHASHMAP>/ and re-created a test to generate the library on the fly.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120645/new/
https://reviews.llvm.org/D120645
Files:
llvm/lib/Object/Archive.cpp
llvm/test/tools/llvm-lib/Inputs/xfghashmap-inserter.py
llvm/test/tools/llvm-lib/xfghashmap-list.test
Index: llvm/test/tools/llvm-lib/xfghashmap-list.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-lib/xfghashmap-list.test
@@ -0,0 +1,14 @@
+RUN: rm -rf %t && mkdir -p %t
+RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/a.obj %S/Inputs/a.s
+RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/b.obj %S/Inputs/b.s
+
+RUN: rm -f %t/xfghash.lib && cd %t
+RUN: llvm-lib /out:xfghashmap.lib a.obj b.obj
+RUN: %python %S/Inputs/xfghashmap-inserter.py xfghashmap.lib b.obj/
+
+# This should print the /<XFGHASHMAP>/ section as well as an .obj one
+RUN: llvm-lib /list %t/xfghashmap.lib | FileCheck %s
+
+CHECK: a.obj
+CHECK: /<XFGHASHMAP>/
+CHECK-NOT: b.obj
Index: llvm/test/tools/llvm-lib/Inputs/xfghashmap-inserter.py
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-lib/Inputs/xfghashmap-inserter.py
@@ -0,0 +1,17 @@
+import sys
+
+if len(sys.argv) < 3:
+ print("Use: xfghashmap-inserter.py <LIBRARY_FILE> <TEMPLATE>")
+ exit(1)
+
+search = bytes(sys.argv[2], 'utf-8')
+xfghashmap = bytes("/<XFGHASHMAP>/", 'utf-8')
+
+data = None
+with open(sys.argv[1], "rb") as inp:
+ data = inp.read()
+with open(sys.argv[1], "wb") as outp:
+ pos = data.find(search)
+ outp.write(data[:pos])
+ outp.write(xfghashmap)
+ outp.write(data[pos + len(xfghashmap):])
Index: llvm/lib/Object/Archive.cpp
===================================================================
--- llvm/lib/Object/Archive.cpp
+++ llvm/lib/Object/Archive.cpp
@@ -256,6 +256,10 @@
return Name;
if (Name.size() == 2 && Name[1] == '/') // String table.
return Name;
+ // System libraries from Windows SDK for Window 11 contain this symbol,
+ // it looks like a CFG guard, we just skip it for now.
+ if (Name.equals("/<XFGHASHMAP>/"))
+ return Name;
// It's a long name.
// Get the string table offset.
std::size_t StringOffset;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120645.412000.patch
Type: text/x-patch
Size: 1979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220301/396801a9/attachment.bin>
More information about the llvm-commits
mailing list