Skip to content

Commit

Permalink
Give end-marker symbols their own addresses to fix a linker bug
Browse files Browse the repository at this point in the history
It seems there is a linker bug related to control-flow guard that is
causing dotnet#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 dotnet#66969
  • Loading branch information
jakobbotsch committed Mar 22, 2022
1 parent a484644 commit f05c8f4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 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 @@ -51,6 +51,8 @@ C_FUNC(\Name):
.macro LEAF_END_MARKED Name, Section
C_FUNC(\Name\()_End):
.global C_FUNC(\Name\()_End)
; make sure this symbol gets its own address

This comment has been minimized.

Copy link
@janvorli

janvorli Mar 22, 2022

Can you please put the nop after the LEAF_END in all cases?

This comment has been minimized.

Copy link
@jakobbotsch

jakobbotsch Mar 22, 2022

Author Owner

Should I also move it for for the existing Windows x64? It currently comes before endp there.

This comment has been minimized.

Copy link
@jakobbotsch

jakobbotsch Mar 22, 2022

Author Owner

I will leave Windows x64 alone but move the others.

This comment has been minimized.

Copy link
@janvorli

janvorli Mar 22, 2022

I think it should be ok to move the Windows x64 too to have it uniform.

nop
LEAF_END \Name, \Section
.endm

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 @@ -39,6 +39,8 @@ C_FUNC(\Name):
.thumb_func
.global C_FUNC(\Name\()_End)
C_FUNC(\Name\()_End):
; make sure this symbol gets its own address
nop
LEAF_END \Name, \Section
.endm

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 @@ -43,6 +43,8 @@ C_FUNC(\Name):
.macro LEAF_END_MARKED Name, Section
C_FUNC(\Name\()_End):
.global C_FUNC(\Name\()_End)
; make sure this symbol gets its own address
nop
LEAF_END \Name, \Section
.endm

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 @@ -32,6 +32,8 @@ C_FUNC(\Name):
.macro LEAF_END_MARKED Name, Section
C_FUNC(\Name\()_End):
.global C_FUNC(\Name\()_End)
; make sure this symbol gets its own address
nop
LEAF_END \Name, \Section
.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 @@ -37,6 +37,8 @@ LEAF_END_MARKED macro functionName
endMarkerName TEXTEQU @CatStr(%bareFunctionName, <_End@0>)
%endMarkerName:
PUBLIC endMarkerName
; make sure this symbol gets its own address
nop
functionName ENDP
endm

Expand Down

0 comments on commit f05c8f4

Please sign in to comment.