Skip to content

Commit

Permalink
sf.net # 997: gcc backend: handle EXTERN "rtlib"
Browse files Browse the repository at this point in the history
- preserve the internally mangled name
- emit an extra prototype to map the internal name to the external ASM name
- previously extern "rtlib" and -gen gcc backend was causing a duplicated
  definition because the defined name was global completely disregarding
  the namespace
- the intent is that the namespace is preserved internally and mapped
  to an external c procedure (i.e. more than one name can alias an existing
  procedure)
  • Loading branch information
jayrm committed Dec 3, 2023
1 parent 54e02ea commit 36650b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -33,6 +33,7 @@ Version 1.20.0
- gas64: NEW UBYTE/BYTE[count] not handled (SARG)
- sf.net #988: (regression) re-allow overloaded non-indexed array arguments - Can't pass UDT member array to an overloaded sub
- gas64: 'SI' word found in cvtsi2ss wrongly releasing RSI register (SARG)
- sf.net #997: gcc backend: handle EXTERN "rtlib": preserve the internally mangled name but emit an extra prototype to map the internal name to the external ASM name


Version 1.10.1
Expand Down
14 changes: 13 additions & 1 deletion src/compiler/ir-hlc.bas
Expand Up @@ -467,7 +467,13 @@ private function hGetMangledNameForASM _

dim as string mangled

mangled = *symbGetMangledName( sym )
'' rtlib mangling? Just use the alias if one was given
if( (symbGetMangling( sym ) = FB_MANGLING_RTLIB) andalso _
(sym->id.alias <> NULL) ) then
mangled = *sym->id.alias
else
mangled = *symbGetMangledName( sym )
end if

if( underscore_prefix and env.underscoreprefix ) then
mangled = "_" + mangled
Expand All @@ -487,6 +493,12 @@ end function
private function hNeedAlias( byval proc as FBSYMBOL ptr ) as integer
function = FALSE

'' rtlib mangling? Expect we always need the asm alias
if( symbGetMangling( proc ) = FB_MANGLING_RTLIB ) then
function = TRUE
exit function
end if

'' Only on systems where gcc would use the @N suffix
if( fbGetCpuFamily( ) <> FB_CPUFAMILY_X86 ) then
exit function
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/symb-mangling.bas
Expand Up @@ -668,7 +668,9 @@ private function hDoCppMangling( byval sym as FBSYMBOL ptr ) as integer
end if

'' extern "rtlib"? disable cpp mangling
if( symbGetMangling( sym ) = FB_MANGLING_RTLIB ) then
if( (symbGetMangling( sym ) = FB_MANGLING_RTLIB) _
andalso (env.clopt.backend <> FB_BACKEND_GCC) _
andalso (sym->id.alias <> NULL) ) then
'' disable cpp mangling only if it's not internally generated:
'' Internally generated symbols:
'' - vtable
Expand Down

0 comments on commit 36650b9

Please sign in to comment.