Than McIntosh has uploaded this change for review.
cmd/link/internal/ld: always pass ASLR options on windows to ext linker
DO NOT SUBMIT
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to --no-dynamicbase (if no
explicit option was given). This assumption doesn't hold for LLD,
which sets --dynamicbase by default for 64-bit apps. Change the linker
code to explicitly pass --dynamicbase either way, so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 46e97e0..50cf490 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -1321,12 +1321,18 @@
}
// Enable ASLR on Windows.
- addASLRargs := func(argv []string) []string {
+ addASLRargs := func(argv []string, val bool) []string {
+ dbopt := "--no-dynamic-base"
+ heopt := "--no-high-entropy-va"
+ if val {
+ dbopt = "--dynamicbase"
+ heopt = "--high-entropy-va"
+ }
// Enable ASLR.
- argv = append(argv, "-Wl,--dynamicbase")
+ argv = append(argv, "-Wl,"+dbopt)
// enable high-entropy ASLR on 64-bit.
if ctxt.Arch.PtrSize >= 8 {
- argv = append(argv, "-Wl,--high-entropy-va")
+ argv = append(argv, "-Wl,"+heopt)
}
return argv
}
@@ -1343,7 +1349,7 @@
switch ctxt.HeadType {
case objabi.Hdarwin, objabi.Haix:
case objabi.Hwindows:
- argv = addASLRargs(argv)
+ argv = addASLRargs(argv, *flagAslr)
default:
// ELF.
if ctxt.UseRelro() {
@@ -1360,9 +1366,7 @@
}
argv = append(argv, "-shared")
if ctxt.HeadType == objabi.Hwindows {
- if *flagAslr {
- argv = addASLRargs(argv)
- }
+ argv = addASLRargs(argv, *flagAslr)
} else {
// Pass -z nodelete to mark the shared library as
// non-closeable: a dlclose will do nothing.
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Than McIntosh uploaded patch set #2 to this change.
cmd/link/internal/ld: always pass ASLR options on windows to ext linker
DO NOT SUBMIT
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to --no-dynamicbase (if no
explicit option was given). This assumption doesn't hold for LLD,
which sets --dynamicbase by default for 64-bit apps. Change the linker
code to explicitly pass --dynamicbase either way, so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 30 insertions(+), 7 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 2:Run-TryBot +1Trust +1
1 comment:
Patchset:
TRY=windows-amd64-longtest,windows-arm64-10,windows-386-2012
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Than McIntosh.
Than McIntosh uploaded patch set #3 to this change.
cmd/link/internal/ld: always pass ASLR options on windows to ext linker
DO NOT SUBMIT
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to --no-dynamicbase (if no
explicit option was given). This assumption doesn't hold for LLD,
which turns on --dynamicbase by default for 64-bit apps. Change the linker
code to explicitly pass --dynamicbase either way, so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 51 insertions(+), 8 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 3:Run-TryBot +1Trust +1
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Than McIntosh uploaded patch set #4 to this change.
cmd/link/internal/ld: always pass ASLR options on windows to ext linker
DO NOT SUBMIT
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to --no-dynamicbase (if no
explicit option was given). This assumption doesn't hold for LLD,
which turns on --dynamicbase by default for 64-bit apps. Change the linker
code to explicitly pass --dynamicbase either way, so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 56 insertions(+), 9 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Than McIntosh uploaded patch set #5 to this change.
cmd/link/internal/ld: always pass ASLR options on windows to ext linker
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to --no-dynamicbase (if no
explicit option was given). This assumption doesn't hold for LLD,
which turns on --dynamicbase by default for 64-bit apps. Change the linker
code to explicitly pass --dynamicbase either way, so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Updates #35006.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 60 insertions(+), 9 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 5:Run-TryBot +1Trust +1
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 6:Run-TryBot +1Trust +1
Attention is currently required from: Than McIntosh.
Than McIntosh uploaded patch set #7 to this change.
cmd/link/internal/ld: always pass ASLR options on windows to ext linker
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to --no-dynamicbase (if no
explicit option was given). This assumption doesn't hold for LLD,
which turns on --dynamicbase by default for 64-bit apps. Change the linker
code to explicitly pass --dynamicbase either way, so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Updates #35006.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 55 insertions(+), 9 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 7:Run-TryBot +1Trust +1
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patchset:
OK, after a number of iterations on this patch, it looks like things are a good deal more complicated than I thought.
With the existing GCC 5.X C compilers installed on our builders, the default (if no other options used) is to have ASLR disabled; if you pass "--dynamicbase" then this turns on ALSR. There is no way to explicitly _disable_ dynamic base on the command line, however: the linker does not accept "--no-dynamicbase" or "--disable-dynamicbase", and [perversely] while it accepts "--dynamicbase=0", this doesn't seem to have any effect. So the _only_ way to get no ASLR is to avoid using any options.
With the more modern compilers (both the clang/lld/LLVM vintage and with GCC 11+) the default is ASLR, so if you don't pass anything, you get ASLR. If you want to disable ASLR, you can pass "--no-dynamicbase" or "--disable-dynamicbase" but "--dynamicbase=0" does not work.
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Than McIntosh uploaded patch set #8 to this change.
cmd/link/internal/ld: always pass ASLR options on windows to ext linker
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to --no-dynamicbase (if no
explicit option was given). This assumption doesn't hold for LLD,
which turns on --dynamicbase by default for 64-bit apps. Change the linker
code to explicitly pass --dynamicbase either way, so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Updates #35006.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 66 insertions(+), 10 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 8:Run-TryBot +1Trust +1
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Than McIntosh.
Than McIntosh uploaded patch set #9 to this change.
cmd/link/internal/ld: revise recipe for ASLR enable on windows
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to --no-dynamicbase (if no
explicit option was given). This assumption doesn't hold for LLD,
which turns on --dynamicbase by default for 64-bit apps. Change the
linker to detect whether a more modern toolchain is in use and to
explicitly pass --dynamicbase either way , so as to take the external
linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Updates #35006.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 67 insertions(+), 10 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 9:Run-TryBot +1Trust +1
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 10:Run-TryBot +1Trust +1
1 comment:
Patchset:
TRY=windows-amd64-longtest,windows-386-2012
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Than McIntosh uploaded patch set #11 to this change.
cmd/link/internal/ld: revise recipe for ASLR enable on windows
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to "--no-dynamicbase" (if
no explicit option was given). This assumption doesn't hold for LLD,
which turns on "--dynamicbase" by default for 64-bit apps. Change the
linker to detect whether a more modern toolchain is in use and to
explicitly pass "--dynamicbase" either way , so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Updates #35006.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 67 insertions(+), 10 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 11:Run-TryBot +1Trust +1
1 comment:
Patchset:
TRY=windows-amd64-longtest,windows-386-2012
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Cherry Mui.
Patch set 18:Trust +1
Attention is currently required from: Cherry Mui.
Patch set 19:Run-TryBot +1Trust +1
Attention is currently required from: Than McIntosh.
Patch set 19:Code-Review +2
2 comments:
File src/cmd/link/internal/ld/lib.go:
Remove this tab?
Patch Set #19, Line 1383: // Test to see whether we
Incomplete comment.
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
2 comments:
File src/cmd/link/internal/ld/lib.go:
Remove this tab?
Done
Patch Set #19, Line 1383: // Test to see whether we
Incomplete comment.
Fixed.
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Than McIntosh uploaded patch set #20 to this change.
cmd/link/internal/ld: revise recipe for ASLR enable on windows
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to "--no-dynamicbase" (if
no explicit option was given). This assumption doesn't hold for LLD,
which turns on "--dynamicbase" by default for 64-bit apps. Change the
linker to detect whether a more modern toolchain is in use and to
explicitly pass "--dynamicbase" either way , so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Updates #35006.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 67 insertions(+), 10 deletions(-)
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 21:Run-TryBot +1Trust +1
1 comment:
Patchset:
TRY=windows-amd64-longtest,windows-amd64-race,windows-arm64-11
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 22:Run-TryBot +1Trust +1
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.
Than McIntosh submitted this change.
19 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: src/cmd/link/internal/ld/lib.go
Insertions: 3, Deletions: 3.
The diff is too large to show. Please review the diff.
```
cmd/link/internal/ld: revise recipe for ASLR enable on windows
When doing external linking on windows, the existing Go linker code
assumed that the external linker defaulted to "--no-dynamicbase" (if
no explicit option was given). This assumption doesn't hold for LLD,
which turns on "--dynamicbase" by default for 64-bit apps. Change the
linker to detect whether a more modern toolchain is in use and to
explicitly pass "--dynamicbase" either way , so as to take the
external linker default out of the equation. This also applies to the
"--high-entropy-va" option as well.
Updates #35006.
Change-Id: I3e12cf6d331c9d003e3d2bd566d45de5710588b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/384156
Reviewed-by: Cherry Mui <cher...@google.com>
Trust: Than McIntosh <th...@google.com>
Run-TryBot: Than McIntosh <th...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>
---
M src/cmd/link/internal/ld/lib.go
1 file changed, 72 insertions(+), 10 deletions(-)
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 6f9c7c2..4295bb8 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -1353,13 +1353,52 @@
argv = append(argv, "-Wl,-bbigtoc")
}
- // Enable ASLR on Windows.
- addASLRargs := func(argv []string) []string {
- // Enable ASLR.
- argv = append(argv, "-Wl,--dynamicbase")
+ // Enable/disable ASLR on Windows.
+ addASLRargs := func(argv []string, val bool) []string {
+ // Old/ancient versions of GCC support "--dynamicbase" and
+ // "--high-entropy-va" but don't enable it by default. In
+ // addition, they don't accept "--disable-dynamicbase" or
+ // "--no-dynamicbase", so the only way to disable ASLR is to
+ // not pass any flags at all.
+ //
+ // More modern versions of GCC (and also clang) enable ASLR
+ // by default. With these compilers, however you can turn it
+ // off if you want using "--disable-dynamicbase" or
+ // "--no-dynamicbase".
+ //
+ // The strategy below is to try using "--disable-dynamicbase";
+ // if this succeeds, then assume we're working with more
+ // modern compilers and act accordingly. If it fails, assume
+ // an ancient compiler with ancient defaults.
+ var dbopt string
+ var heopt string
+ dbon := "--dynamicbase"
+ heon := "--high-entropy-va"
+ dboff := "--disable-dynamicbase"
+ heoff := "--disable-high-entropy-va"
+ if val {
+ dbopt = dbon
+ heopt = heon
+ } else {
+ // Test to see whether "--disable-dynamicbase" works.
+ newer := linkerFlagSupported(ctxt.Arch, argv[0], "", "-Wl,"+dboff)
+ if newer {
+ // Newer compiler, which supports both on/off options.
+ dbopt = dboff
+ heopt = heoff
+ } else {
+ // older toolchain: we have to say nothing in order to
+ // get a no-ASLR binary.
+ dbopt = ""
+ heopt = ""
+ }
+ }
+ if dbopt != "" {
+ argv = append(argv, "-Wl,"+dbopt)
+ }
// enable high-entropy ASLR on 64-bit.
- if ctxt.Arch.PtrSize >= 8 {
- argv = append(argv, "-Wl,--high-entropy-va")
+ if ctxt.Arch.PtrSize >= 8 && heopt != "" {
+ argv = append(argv, "-Wl,"+heopt)
}
return argv
}
@@ -1376,7 +1415,7 @@
switch ctxt.HeadType {
case objabi.Hdarwin, objabi.Haix:
case objabi.Hwindows:
- argv = addASLRargs(argv)
+ argv = addASLRargs(argv, *flagAslr)
default:
// ELF.
if ctxt.UseRelro() {
@@ -1393,9 +1432,7 @@
}
argv = append(argv, "-shared")
if ctxt.HeadType == objabi.Hwindows {
- if *flagAslr {
- argv = addASLRargs(argv)
- }
+ argv = addASLRargs(argv, *flagAslr)
} else {
// Pass -z nodelete to mark the shared library as
// non-closeable: a dlclose will do nothing.
To view, visit change 384156. To unsubscribe, or for help writing mail filters, visit settings.