Skip to content

Commit

Permalink
Give end-marker symbols their own addresses to work around a linker b…
Browse files Browse the repository at this point in the history
…ug (#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
  • Loading branch information
jakobbotsch committed Mar 23, 2022
1 parent 9cd49ff commit 2724b7e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/pal/inc/unixasmmacrosamd64.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/pal/inc/unixasmmacrosarm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/pal/inc/unixasmmacrosarm64.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/pal/inc/unixasmmacrosx86.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/vm/amd64/AsmMacros.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/arm/asmmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ __EndLabelName SETS "$FuncName":CC:"_End"

LEAF_END $FuncName

; Make sure this symbol gets its own address
nop

MEND

;-----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/arm64/asmmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/i386/AsmMacros.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2724b7e

Please sign in to comment.