Skip to content

Commit 12a4d28

Browse files
committed
LLVM backend: escape procedure names on win32 targets to avoid having llvm mangle the names also
Escape global procedure names for windows targets on LLVM. - For gas backend we always use the mangled name as-is. - For gcc backend we sort of let gcc do it but also supply an asm alias where the gcc might get it wrong calculating the suffix - escape the mangled name even if there is no @n suffix due the leading underscore handling Not tested: global variable identifiers, g++ mangling
1 parent 46b0060 commit 12a4d28

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Version 1.08.0
110110
- various HANDLE_WM_*, FORWARD_WM_* macros in win/windowsx.bi were broken
111111
- gcc backend was trying to pass single types to double typed built-ins
112112
- gfxlib2: character data was incorrectly stored for values >= 128 causing incorrect values returned from SCREEN() function
113+
- LLVM backend: escape procedure names on win32 targets to avoid having llvm mangle the names also
113114

114115

115116
Version 1.07.0

src/compiler/symb-mangling.bas

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ end function
11941194
private sub hMangleProc( byval sym as FBSYMBOL ptr )
11951195
dim as string mangled
11961196
dim as integer length = any, docpp = any, add_stdcall_suffix = any
1197+
dim as integer quote_mangled_name = false
11971198
dim as zstring ptr id = any
11981199

11991200
docpp = hDoCppMangling( sym )
@@ -1212,11 +1213,33 @@ private sub hMangleProc( byval sym as FBSYMBOL ptr )
12121213
if( env.clopt.backend = FB_BACKEND_LLVM ) then
12131214
mangled += "@"
12141215

1216+
'' TODO: should be able to clean up this logic where we have a windows
1217+
'' target and remove the check on 'add_stdcall_suffix' here.
1218+
'' on win we are also quoting and escaping and should not need to quote
1219+
'' only or have @N suffix only on any other target.
1220+
12151221
'' Going to add @N stdcall suffix below?
1222+
'' In LLVM, @ is a special char, identifiers using it must be quoted
12161223
if( add_stdcall_suffix ) then
1217-
'' In LLVM, @ is a special char, identifiers using it must be quoted
12181224
mangled += """"
1225+
quote_mangled_name = true
12191226
end if
1227+
1228+
'' Windows target also? we provide the mangling so the name
1229+
'' must be both quoted and escaped so that our mangled name does not
1230+
'' get mangled again by llvm. we need to do this on all names
1231+
'' not just the ones with @N suffix due the leading underscore handling
1232+
select case( env.clopt.target )
1233+
case FB_COMPTARGET_WIN32, FB_COMPTARGET_CYGWIN, FB_COMPTARGET_XBOX
1234+
if( quote_mangled_name = false ) then
1235+
mangled += """"
1236+
quote_mangled_name = true
1237+
end if
1238+
1239+
'' chr(1) will escape the name so it's passed through to assembler as-is
1240+
mangled += chr(1)
1241+
end select
1242+
12201243
end if
12211244

12221245
'' Win32 underscore prefix
@@ -1301,11 +1324,11 @@ private sub hMangleProc( byval sym as FBSYMBOL ptr )
13011324
'' @N win32 stdcall suffix
13021325
if( add_stdcall_suffix ) then
13031326
mangled += "@" + str( symbProcCalcStdcallSuffixN( sym ) )
1327+
end if
13041328

1305-
if( env.clopt.backend = FB_BACKEND_LLVM ) then
1306-
'' In LLVM, @ is a special char, identifiers using it must be quoted
1307-
mangled += """"
1308-
end if
1329+
'' close the quoted name if needed
1330+
if( quote_mangled_name ) then
1331+
mangled += """"
13091332
end if
13101333

13111334
symbSetMangledId( sym, mangled )

0 commit comments

Comments
 (0)