-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lld][COFF] Merge .00cfg section into .rdata. #75207
Conversation
.00cfg section is used by crt for load config and is merged by MS link.exe into .rdata.
@llvm/pr-subscribers-lld-coff Author: Jacek Caban (cjacek) Changes.00cfg section is used by crt for load config and is merged by MS link.exe into .rdata. cc @bylaws Full diff: https://github.com/llvm/llvm-project/pull/75207.diff 4 Files Affected:
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 99c1a60735adc5..d4a2f5767a2e87 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1940,6 +1940,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
parseMerge(".didat=.rdata");
parseMerge(".edata=.rdata");
parseMerge(".xdata=.rdata");
+ parseMerge(".00cfg=.rdata");
parseMerge(".bss=.data");
if (config->mingw) {
diff --git a/lld/test/COFF/Inputs/loadconfig-arm64ec.s b/lld/test/COFF/Inputs/loadconfig-arm64ec.s
index 8bb5ccfed8ebc8..a270d281095dd6 100644
--- a/lld/test/COFF/Inputs/loadconfig-arm64ec.s
+++ b/lld/test/COFF/Inputs/loadconfig-arm64ec.s
@@ -1,4 +1,4 @@
- .section .rdata,"dr"
+ .section .00cfg,"dr"
.globl _load_config_used
.p2align 3, 0
_load_config_used:
diff --git a/lld/test/COFF/Inputs/loadconfig-cfg-x64.s b/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
index 1440b115f46ad4..349d8c5a8db36e 100644
--- a/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
+++ b/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
@@ -1,6 +1,6 @@
# This is the _load_config_used definition needed for /guard:cf tests.
- .section .rdata,"dr"
+ .section .00cfg,"dr"
.globl _load_config_used
_load_config_used:
.long 256
diff --git a/lld/test/COFF/merge-00cfg.s b/lld/test/COFF/merge-00cfg.s
new file mode 100644
index 00000000000000..89a4c8f0834210
--- /dev/null
+++ b/lld/test/COFF/merge-00cfg.s
@@ -0,0 +1,17 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t-x86_64.obj
+// RUN: llvm-mc -filetype=obj -triple=i686-windows %s -o %t-x86.obj
+// RUN: lld-link -machine:amd64 -out:%t-x86_64.dll %t-x86_64.obj -dll -noentry
+// RUN: lld-link -machine:x86 -out:%t-x86.dll %t-x86.obj -dll -noentry -safeseh:no
+
+// RUN: llvm-readobj --hex-dump=.rdata %t-x86_64.dll | FileCheck %s -check-prefix=RDATA
+// RUN: llvm-readobj --hex-dump=.rdata %t-x86.dll | FileCheck %s -check-prefix=RDATA
+// RDATA: 78563412
+
+// RUN: llvm-readobj --sections %t-x86_64.dll | FileCheck %s -check-prefix=SECTIONS
+// RUN: llvm-readobj --sections %t-x86.dll | FileCheck %s -check-prefix=SECTIONS
+// SECTIONS-NOT: .00cfg
+
+ .section ".00cfg", "dr"
+ .long 0x12345678
|
@llvm/pr-subscribers-platform-windows Author: Jacek Caban (cjacek) Changes.00cfg section is used by crt for load config and is merged by MS link.exe into .rdata. cc @bylaws Full diff: https://github.com/llvm/llvm-project/pull/75207.diff 4 Files Affected:
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 99c1a60735adc..d4a2f5767a2e8 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1940,6 +1940,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
parseMerge(".didat=.rdata");
parseMerge(".edata=.rdata");
parseMerge(".xdata=.rdata");
+ parseMerge(".00cfg=.rdata");
parseMerge(".bss=.data");
if (config->mingw) {
diff --git a/lld/test/COFF/Inputs/loadconfig-arm64ec.s b/lld/test/COFF/Inputs/loadconfig-arm64ec.s
index 8bb5ccfed8ebc..a270d281095dd 100644
--- a/lld/test/COFF/Inputs/loadconfig-arm64ec.s
+++ b/lld/test/COFF/Inputs/loadconfig-arm64ec.s
@@ -1,4 +1,4 @@
- .section .rdata,"dr"
+ .section .00cfg,"dr"
.globl _load_config_used
.p2align 3, 0
_load_config_used:
diff --git a/lld/test/COFF/Inputs/loadconfig-cfg-x64.s b/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
index 1440b115f46ad..349d8c5a8db36 100644
--- a/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
+++ b/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
@@ -1,6 +1,6 @@
# This is the _load_config_used definition needed for /guard:cf tests.
- .section .rdata,"dr"
+ .section .00cfg,"dr"
.globl _load_config_used
_load_config_used:
.long 256
diff --git a/lld/test/COFF/merge-00cfg.s b/lld/test/COFF/merge-00cfg.s
new file mode 100644
index 0000000000000..89a4c8f083421
--- /dev/null
+++ b/lld/test/COFF/merge-00cfg.s
@@ -0,0 +1,17 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t-x86_64.obj
+// RUN: llvm-mc -filetype=obj -triple=i686-windows %s -o %t-x86.obj
+// RUN: lld-link -machine:amd64 -out:%t-x86_64.dll %t-x86_64.obj -dll -noentry
+// RUN: lld-link -machine:x86 -out:%t-x86.dll %t-x86.obj -dll -noentry -safeseh:no
+
+// RUN: llvm-readobj --hex-dump=.rdata %t-x86_64.dll | FileCheck %s -check-prefix=RDATA
+// RUN: llvm-readobj --hex-dump=.rdata %t-x86.dll | FileCheck %s -check-prefix=RDATA
+// RDATA: 78563412
+
+// RUN: llvm-readobj --sections %t-x86_64.dll | FileCheck %s -check-prefix=SECTIONS
+// RUN: llvm-readobj --sections %t-x86.dll | FileCheck %s -check-prefix=SECTIONS
+// SECTIONS-NOT: .00cfg
+
+ .section ".00cfg", "dr"
+ .long 0x12345678
|
@llvm/pr-subscribers-lld Author: Jacek Caban (cjacek) Changes.00cfg section is used by crt for load config and is merged by MS link.exe into .rdata. cc @bylaws Full diff: https://github.com/llvm/llvm-project/pull/75207.diff 4 Files Affected:
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 99c1a60735adc..d4a2f5767a2e8 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1940,6 +1940,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
parseMerge(".didat=.rdata");
parseMerge(".edata=.rdata");
parseMerge(".xdata=.rdata");
+ parseMerge(".00cfg=.rdata");
parseMerge(".bss=.data");
if (config->mingw) {
diff --git a/lld/test/COFF/Inputs/loadconfig-arm64ec.s b/lld/test/COFF/Inputs/loadconfig-arm64ec.s
index 8bb5ccfed8ebc..a270d281095dd 100644
--- a/lld/test/COFF/Inputs/loadconfig-arm64ec.s
+++ b/lld/test/COFF/Inputs/loadconfig-arm64ec.s
@@ -1,4 +1,4 @@
- .section .rdata,"dr"
+ .section .00cfg,"dr"
.globl _load_config_used
.p2align 3, 0
_load_config_used:
diff --git a/lld/test/COFF/Inputs/loadconfig-cfg-x64.s b/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
index 1440b115f46ad..349d8c5a8db36 100644
--- a/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
+++ b/lld/test/COFF/Inputs/loadconfig-cfg-x64.s
@@ -1,6 +1,6 @@
# This is the _load_config_used definition needed for /guard:cf tests.
- .section .rdata,"dr"
+ .section .00cfg,"dr"
.globl _load_config_used
_load_config_used:
.long 256
diff --git a/lld/test/COFF/merge-00cfg.s b/lld/test/COFF/merge-00cfg.s
new file mode 100644
index 0000000000000..89a4c8f083421
--- /dev/null
+++ b/lld/test/COFF/merge-00cfg.s
@@ -0,0 +1,17 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t-x86_64.obj
+// RUN: llvm-mc -filetype=obj -triple=i686-windows %s -o %t-x86.obj
+// RUN: lld-link -machine:amd64 -out:%t-x86_64.dll %t-x86_64.obj -dll -noentry
+// RUN: lld-link -machine:x86 -out:%t-x86.dll %t-x86.obj -dll -noentry -safeseh:no
+
+// RUN: llvm-readobj --hex-dump=.rdata %t-x86_64.dll | FileCheck %s -check-prefix=RDATA
+// RUN: llvm-readobj --hex-dump=.rdata %t-x86.dll | FileCheck %s -check-prefix=RDATA
+// RDATA: 78563412
+
+// RUN: llvm-readobj --sections %t-x86_64.dll | FileCheck %s -check-prefix=SECTIONS
+// RUN: llvm-readobj --sections %t-x86.dll | FileCheck %s -check-prefix=SECTIONS
+// SECTIONS-NOT: .00cfg
+
+ .section ".00cfg", "dr"
+ .long 0x12345678
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking into this, this has been a longstanding known issue.
@@ -1,4 +1,4 @@ | |||
.section .rdata,"dr" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we lose test coverage by removing .rdata
? If not, LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't lose coverage. We still have other tests that declare _load_config_used in .rdata, so we should be protected from somehow accidentally depending on it being in .00cfg. I made the change to Inputs/ to widen coverage of merging and making shared load config more similar to real-world case feels right.
Thanks for reviews!
.00cfg section is used by crt for load config and is merged by MS link.exe into .rdata.
cc @bylaws