Skip to content

Commit 97d2319

Browse files
committed
fbc: name mangling for cva_list name mangling with arm32 and arm64 (aarch64) targets
- va_list on arm and aarch64 is actually in the std namespace requiring "St" to mangle "std::" (cherry picked from commit 3fe5cd5)
1 parent b674584 commit 97d2319

File tree

10 files changed

+59
-55
lines changed

10 files changed

+59
-55
lines changed

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Version 1.07.2
2020
- sf.net #925: CSIGN/CUNSG preserve size when converting pointers on 64-bit and implict conversion of STEP value in FOR...NEXT statement
2121
- github #122: gfxlib2: linux GFX_NO_FRAME + GFX_OPENGL freezing at exit due to a dead lock between exit routines
2222
- use the multi-byte & wide character functions wctombs() & mbtowcs() when converting between string and wstring (Skyfish)
23-
- read objinfo for elf format files on arm32 and arm64 (aarch64) to allow automatic options and linking of libraries
23+
- fbc: read objinfo for elf format files on arm32 and arm64 (aarch64) to allow automatic options and linking of libraries
24+
- fbc: name mangling for cva_list name mangling with arm32 and arm64 (aarch64) targets
2425

2526

2627
Version 1.07.1

src/compiler/fb.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ function fbGetBackendValistType _
15191519
end select
15201520

15211521
case FB_CPUFAMILY_ARM
1522-
typedef = FB_CVA_LIST_BUILTIN_POINTER
1522+
typedef = FB_CVA_LIST_BUILTIN_ARM
15231523

15241524
case FB_CPUFAMILY_AARCH64
15251525
typedef = FB_CVA_LIST_BUILTIN_AARCH64

src/compiler/fb.bi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ enum FB_CVA_LIST_TYPEDEF
489489
FB_CVA_LIST_BUILTIN_POINTER
490490
FB_CVA_LIST_BUILTIN_C_STD
491491
FB_CVA_LIST_BUILTIN_AARCH64
492+
FB_CVA_LIST_BUILTIN_ARM
492493
end enum
493494

494495
declare function fbGetBackendValistType () as FB_CVA_LIST_TYPEDEF

src/compiler/ir-hlc.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ private function hGetUdtId( byval sym as FBSYMBOL ptr ) as string
652652

653653
'' gcc's __builtin_va_list needs an exact name
654654
select case symbGetValistType( symbGetFullType( sym ), symbGetSubtype( sym ) )
655-
case FB_CVA_LIST_BUILTIN_C_STD, FB_CVA_LIST_BUILTIN_AARCH64
655+
case FB_CVA_LIST_BUILTIN_C_STD, FB_CVA_LIST_BUILTIN_AARCH64, FB_CVA_LIST_BUILTIN_ARM
656656
function = *sym->id.alias
657657
exit function
658658
end select

src/compiler/parser-decl-symbtype.bas

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ private function cMangleModifier _
459459
errReport( FB_ERRMSG_SYNTAXERROR )
460460
end select
461461

462-
case "__builtin_va_list"
462+
case "__builtin_va_list", "__builtin_va_list[]"
463463
select case dtype
464464
case FB_DATATYPE_VOID
465465
dtype = typeSetMangleDt( dtype, FB_DATATYPE_VA_LIST )
@@ -471,19 +471,7 @@ private function cMangleModifier _
471471
'' now just back patch the original struct and
472472
'' remember to document this on mangle modifier page.
473473
'' subtype = symbCloneSymbol( subtype )
474-
symbSetUdtIsValistStruct( subtype )
475-
case else
476-
errReport( FB_ERRMSG_SYNTAXERROR )
477-
end select
478-
479-
case "__builtin_va_list[]"
480-
select case dtype
481-
case FB_DATATYPE_STRUCT
482-
dtype = typeSetMangleDt( dtype, FB_DATATYPE_VA_LIST )
483-
'' TODO: don't clone, see note above.
484-
''subtype = symbCloneSymbol( subtype )
485-
symbSetUdtIsValistStruct( subtype )
486-
symbSetUdtIsValistStructArray( subtype )
474+
symbSetUdtValistType( subtype, fbGetBackendValistType() )
487475
case else
488476
errReport( FB_ERRMSG_SYNTAXERROR )
489477
end select

src/compiler/parser-proc.bas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,16 @@ sub cProcRetType _
447447
case FB_DATATYPE_STRUCT
448448
'' __builtin_va_list[] not allowed as a byval return type
449449
if( subtype ) then
450-
if( symbGetUdtIsValistStructArray( subtype ) ) then
450+
select case symbGetUdtValistType( subtype )
451+
case FB_CVA_LIST_BUILTIN_C_STD
451452
if( ((pattrib and FB_PROCATTRIB_RETURNBYREF) = 0) and _
452453
typeIsPtr( dtype ) = FALSE ) then
453454
errReport( FB_ERRMSG_INVALIDDATATYPES )
454455
'' error recovery: fake a type
455456
dtype = typeAddrOf( dtype )
456457
subtype = NULL
457458
end if
458-
end if
459+
end select
459460
end if
460461

461462
end select

src/compiler/symb-keyword.bas

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,7 @@ sub symbKeywordTypeInit( )
485485
'' subtype mangle modifier
486486
'' don't clone struct, back patch the original only, see note in cMangleModifier()
487487
'' TODO: s = symbCloneSymbol( s )
488-
symbSetUdtIsValistStruct( s )
489-
symbSetUdtIsValistStructArray( s )
488+
symbSetUdtValistType( s, FB_CVA_LIST_BUILTIN_C_STD )
490489

491490
'' type cva_list as __va_list_tag alias "__builtin_va_list[]"
492491
symbAddTypedef( pid, typeSetMangleDt( symbGetType( s ), FB_DATATYPE_VA_LIST ), s, symbGetLen( s ) )
@@ -524,7 +523,29 @@ sub symbKeywordTypeInit( )
524523
'' subtype mangle modifier
525524
'' don't clone struct, back patch the original only, see note in cMangleModifier()
526525
'' TODO: s = symbCloneSymbol( s )
527-
symbSetUdtIsValistStruct( s )
526+
symbSetUdtValistType( s, FB_CVA_LIST_BUILTIN_AARCH64 )
527+
528+
'' type cva_list as __va_list alias "__builtin_va_list"
529+
symbAddTypedef( pid, typeSetMangleDt( symbGetType( s ), FB_DATATYPE_VA_LIST ), s, symbGetLen( s ) )
530+
531+
case FB_CVA_LIST_BUILTIN_ARM
532+
'' cva_list is from ARM definition:
533+
'' typdef struct __va_list {
534+
'' void *ap;
535+
'' } va_list;
536+
537+
s = symbStructBegin( NULL, NULL, NULL, "__va_list", "__va_list", FALSE, 0, FALSE, 0, 0 )
538+
539+
'' ap as any ptr
540+
symbAddField( s, "ap", 0, dTB(), typeAddrOf( FB_DATATYPE_VOID ), NULL, 0, 0, 0 )
541+
542+
'' end type
543+
symbStructEnd( s )
544+
545+
'' subtype mangle modifier
546+
'' don't clone struct, back patch the original only, see note in cMangleModifier()
547+
'' TODO: s = symbCloneSymbol( s )
548+
symbSetUdtValistType( s, FB_CVA_LIST_BUILTIN_ARM )
528549

529550
'' type cva_list as __va_list alias "__builtin_va_list"
530551
symbAddTypedef( pid, typeSetMangleDt( symbGetType( s ), FB_DATATYPE_VA_LIST ), s, symbGetLen( s ) )

src/compiler/symb-mangling.bas

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,20 +509,29 @@ sub symbMangleType _
509509
if( typeGetDtOnly( dtype ) = FB_DATATYPE_STRUCT ) then
510510
if( typeGetMangleDt( dtype ) = FB_DATATYPE_VA_LIST ) then
511511

512-
'' if the type was passed as byval ptr or byref
513-
'' need to mangle in "A1_" to indicate the array type, but
514-
'' not on aarch64, __va_list is a plain struct, it doesn't
515-
'' need the array type specifier.
512+
select case symbGetValistType( dtype, subtype )
513+
case FB_CVA_LIST_BUILTIN_C_STD
514+
'' if the type was passed as byval ptr or byref
515+
'' need to mangle in "A1_" to indicate the array type, but
516+
'' not on aarch64, __va_list is a plain struct, it doesn't
517+
'' need the array type specifier.
516518

517-
if( symbIsValistStructArray( dtype, subtype ) ) then
518519
if( (options and (FB_MANGLEOPT_HASREF or FB_MANGLEOPT_HASPTR)) <> 0 ) then
519520
mangled += "A1_"
520521
else
521522
mangled += "P"
522523
end if
523-
end if
524+
dtype = typeSetMangleDt( dtype, 0 )
525+
526+
case FB_CVA_LIST_BUILTIN_AARCH64, FB_CVA_LIST_BUILTIN_ARM
527+
'' on arm and aarch targets, __builtin_va_list actually
528+
'' maps to "std::__va_list" where "std::" has the mangling
529+
'' identifier of "St"
530+
531+
mangled += "St"
532+
dtype = typeSetMangleDt( dtype, 0 )
524533

525-
dtype = typeSetMangleDt( dtype, 0 )
534+
end select
526535
end if
527536
end if
528537
end if
@@ -532,7 +541,7 @@ sub symbMangleType _
532541
''
533542
assert( dtype = (typeGetDtOnly( dtype ) or (dtype and FB_DT_MANGLEMASK)) )
534543

535-
select case( dtype )
544+
select case( typeGetDtOnly( dtype ) )
536545
case FB_DATATYPE_STRUCT, FB_DATATYPE_ENUM
537546
ns = symbGetNamespace( subtype )
538547
if( ns = @symbGetGlobalNamespc( ) ) then

src/compiler/symb.bas

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,7 @@ function symbGetValistType _
16131613
'' with a UDT subtype, or we might be looking at the UDT
16141614
'' itself. Either way, we must look at the UDT itself to
16151615
'' determine if it is a struct or struct array type using
1616-
'' - symbGetUdtIsValistStruct()
1617-
'' - symbGetUdtIsValistStructArray()
1616+
'' - symbGetUdtValistType()
16181617

16191618
'' Determine the following:
16201619
'' 1) va_list type? (any target/va_list type)
@@ -1633,13 +1632,7 @@ function symbGetValistType _
16331632

16341633
case FB_DATATYPE_STRUCT
16351634
if( subtype ) then
1636-
if( symbGetUdtIsValistStruct( subtype ) ) then
1637-
if( symbGetUdtIsValistStructArray( subtype ) ) then
1638-
function = FB_CVA_LIST_BUILTIN_C_STD
1639-
else
1640-
function = FB_CVA_LIST_BUILTIN_AARCH64
1641-
end if
1642-
end if
1635+
function = symbGetUdtValistType( subtype )
16431636
end if
16441637

16451638
case else
@@ -1661,13 +1654,7 @@ function symbGetValistType _
16611654
end if
16621655

16631656
case FB_DATATYPE_STRUCT
1664-
if( symbGetUdtIsValistStruct( subtype ) ) then
1665-
if( symbGetUdtIsValistStructArray( subtype ) ) then
1666-
function = FB_CVA_LIST_BUILTIN_C_STD
1667-
else
1668-
function = FB_CVA_LIST_BUILTIN_AARCH64
1669-
end if
1670-
end if
1657+
function = symbGetUdtValistType( subtype )
16711658

16721659
end select
16731660

src/compiler/symb.bi

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,9 @@ enum FB_UDTOPT
448448
FB_UDTOPT_HASANONUNION = &h2000
449449
FB_UDTOPT_HASSTATICVAR = &h4000
450450
FB_UDTOPT_HASBITFIELD = &h8000
451-
FB_UDTOPT_ISVALISTSTRUCT = &h10000
452-
FB_UDTOPT_ISVALISTSTRUCTARRAY = &h20000
453-
FB_UDTOPT_ISWSTRING = &h40000
454-
FB_UDTOPT_ISZSTRING = &h80000
451+
FB_UDTOPT_ISWSTRING = &h10000
452+
FB_UDTOPT_ISZSTRING = &h20000
453+
FB_UDTOPT_VALISTTYPEMASK = &hf00000
455454
end enum
456455

457456
type FB_STRUCT_DBG
@@ -2272,11 +2271,8 @@ declare function symbCloneSimpleStruct( byval sym as FBSYMBOL ptr ) as FBSYMBOL
22722271
#define symbSetUdtHasBitfield( s ) (s)->udt.options or= FB_UDTOPT_HASBITFIELD
22732272
#define symbGetUdtHasBitfield( s ) (((s)->udt.options and FB_UDTOPT_HASBITFIELD) <> 0)
22742273

2275-
#define symbSetUdtIsValistStruct( s ) (s)->udt.options or= FB_UDTOPT_ISVALISTSTRUCT
2276-
#define symbGetUdtIsValistStruct( s ) (((s)->udt.options and FB_UDTOPT_ISVALISTSTRUCT) <> 0)
2277-
2278-
#define symbSetUdtIsValistStructArray( s ) (s)->udt.options or= FB_UDTOPT_ISVALISTSTRUCTARRAY
2279-
#define symbGetUdtIsValistStructArray( s ) (((s)->udt.options and FB_UDTOPT_ISVALISTSTRUCTARRAY) <> 0)
2274+
#define symbSetUdtValistType( s, t ) (s)->udt.options or= (((t) shl 20) and FB_UDTOPT_VALISTTYPEMASK)
2275+
#define symbGetUdtValistType( s ) (((s)->udt.options and FB_UDTOPT_VALISTTYPEMASK) shr 20)
22802276

22812277
#define symbSetUdtIsZstring( s ) (s)->udt.options or= FB_UDTOPT_ISZSTRING
22822278
#define symbGetUdtIsZstring( s ) (((s)->udt.options and FB_UDTOPT_ISZSTRING) <> 0 )

0 commit comments

Comments
 (0)