From 2724b7ef5a4987ba382d4a3c934b1d42dfcff8c1 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 23 Mar 2022 18:13:00 +0100 Subject: [PATCH] Give end-marker symbols their own addresses to work around a linker bug (#66999) It seems there is a linker bug related to control-flow guard that is causing #66969. In eb8460f a thunktemplates.asm file was added that has a LEAF_END_MARKED at the end of the file. This creates two symbols for the same upcoming address. Normally that should be fine, but in this case it causes the linker to place the same address twice in a CFG table in the PE file. This causes the kernel to fail while loading the image. A simple workaround would be to add a nop at the end of thunktemplates.asm, but @janvorli suggested giving these symbols their own address in all cases for goodness when debugging. We already do so for Windows x64 it looks like. Fix #66969 --- src/coreclr/pal/inc/unixasmmacrosamd64.inc | 2 ++ src/coreclr/pal/inc/unixasmmacrosarm.inc | 2 ++ src/coreclr/pal/inc/unixasmmacrosarm64.inc | 2 ++ src/coreclr/pal/inc/unixasmmacrosx86.inc | 2 ++ src/coreclr/vm/amd64/AsmMacros.inc | 5 +++-- src/coreclr/vm/arm/asmmacros.h | 3 +++ src/coreclr/vm/arm64/asmmacros.h | 3 +++ src/coreclr/vm/i386/AsmMacros.inc | 2 ++ 8 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/coreclr/pal/inc/unixasmmacrosamd64.inc b/src/coreclr/pal/inc/unixasmmacrosamd64.inc index 2aca375faa8383..bb1e70a27bef02 100644 --- a/src/coreclr/pal/inc/unixasmmacrosamd64.inc +++ b/src/coreclr/pal/inc/unixasmmacrosamd64.inc @@ -52,6 +52,8 @@ C_FUNC(\Name): C_FUNC(\Name\()_End): .global C_FUNC(\Name\()_End) LEAF_END \Name, \Section + // make sure this symbol gets its own address + nop .endm .macro NOP_6_BYTE diff --git a/src/coreclr/pal/inc/unixasmmacrosarm.inc b/src/coreclr/pal/inc/unixasmmacrosarm.inc index d323ccc49fbd2d..f5eb32656cd3ae 100644 --- a/src/coreclr/pal/inc/unixasmmacrosarm.inc +++ b/src/coreclr/pal/inc/unixasmmacrosarm.inc @@ -40,6 +40,8 @@ C_FUNC(\Name): .global C_FUNC(\Name\()_End) C_FUNC(\Name\()_End): LEAF_END \Name, \Section + // make sure this symbol gets its own address + nop .endm .macro PREPARE_EXTERNAL_VAR Name, HelperReg diff --git a/src/coreclr/pal/inc/unixasmmacrosarm64.inc b/src/coreclr/pal/inc/unixasmmacrosarm64.inc index 9545afb9f8e584..8b3c5803b7d71f 100644 --- a/src/coreclr/pal/inc/unixasmmacrosarm64.inc +++ b/src/coreclr/pal/inc/unixasmmacrosarm64.inc @@ -44,6 +44,8 @@ C_FUNC(\Name): C_FUNC(\Name\()_End): .global C_FUNC(\Name\()_End) LEAF_END \Name, \Section + // make sure this symbol gets its own address + nop .endm .macro PREPARE_EXTERNAL_VAR Name, HelperReg diff --git a/src/coreclr/pal/inc/unixasmmacrosx86.inc b/src/coreclr/pal/inc/unixasmmacrosx86.inc index 87cbddd6eda204..7bc994a779c356 100644 --- a/src/coreclr/pal/inc/unixasmmacrosx86.inc +++ b/src/coreclr/pal/inc/unixasmmacrosx86.inc @@ -33,6 +33,8 @@ C_FUNC(\Name): C_FUNC(\Name\()_End): .global C_FUNC(\Name\()_End) LEAF_END \Name, \Section + // make sure this symbol gets its own address + nop .endm .macro PROLOG_BEG diff --git a/src/coreclr/vm/amd64/AsmMacros.inc b/src/coreclr/vm/amd64/AsmMacros.inc index 32d8ecb4fe70ed..2d14b9c31e8fca 100644 --- a/src/coreclr/vm/amd64/AsmMacros.inc +++ b/src/coreclr/vm/amd64/AsmMacros.inc @@ -133,12 +133,13 @@ Section ends LEAF_END_MARKED macro Name, section public Name&_End Name&_End label qword + +Name endp + ; this nop is important to keep the label in ; the right place in the face of BBT nop -Name endp - Section ends endm diff --git a/src/coreclr/vm/arm/asmmacros.h b/src/coreclr/vm/arm/asmmacros.h index ad3826cd8b2e1d..2c07bfb3fd00c8 100644 --- a/src/coreclr/vm/arm/asmmacros.h +++ b/src/coreclr/vm/arm/asmmacros.h @@ -29,6 +29,9 @@ __EndLabelName SETS "$FuncName":CC:"_End" LEAF_END $FuncName + ; Make sure this symbol gets its own address + nop + MEND ;----------------------------------------------------------------------------- diff --git a/src/coreclr/vm/arm64/asmmacros.h b/src/coreclr/vm/arm64/asmmacros.h index fae7ec3309aeec..bd19b9e6dc3dc5 100644 --- a/src/coreclr/vm/arm64/asmmacros.h +++ b/src/coreclr/vm/arm64/asmmacros.h @@ -147,6 +147,9 @@ __EndLabelName SETS "$FuncName":CC:"_End" LEAF_END $FuncName + ; make sure this symbol gets its own address + nop + MEND ;----------------------------------------------------------------------------- ; Macro use for enabling C++ to know where to patch code at runtime. diff --git a/src/coreclr/vm/i386/AsmMacros.inc b/src/coreclr/vm/i386/AsmMacros.inc index ac77064f0da5cc..ba6cc7e81a2854 100644 --- a/src/coreclr/vm/i386/AsmMacros.inc +++ b/src/coreclr/vm/i386/AsmMacros.inc @@ -38,6 +38,8 @@ LEAF_END_MARKED macro functionName %endMarkerName: PUBLIC endMarkerName functionName ENDP + ; make sure this symbol gets its own address + nop endm PATCH_LABEL macro labelName