fbc 32bit still mangles Integer=int and Long=long, which is the opposite of 64bit (Integer=long|INTEGER and Long=int) and the C/C++ binding recommendations.
This means that the same FB and C++ code will only work together on either 32bit or 64bit, but not both.
'' currently works on 32bit only
extern "C++"
declare sub f(byval i as integer)
end extern
...
void f(int i) {
}
'' currently works on 64bit only
extern "C++"
declare sub f(byval i as long)
end extern
...
void f(int i) {
}
This affects the namespace/cpp test case in the FB test suite.
Diff:
It would be good to fix this for C++ compatibility, but unfortunately that would break every existing precompiled FB library that uses Integers and mangling...
I had a note somewhere about mangling in extern blocks, but can't find where I put it. It is somewhat related to this issue; even though fbc might be able to resolve [u]long, [u]integer, [u]longint overloads, fbc should respect the capabilities of the extern's linker namespace.
There is a possible fix here that improves compatibility with C++, but as mentioned, it breaks compatibility with previous FB versions, so I'm not sure it's a good idea.
I think the change is acceptable is worth the trouble of breaking compatibility. Goal is to write code in FB and code in C++ that is compatible at the binary (linker) level, and this change moves us closer to that goal. We don't have to change FB mangling, but in this case it makes sense to align it with the recommendations.
Here's my notes, about the mangling, that helped me understand, and other problems.
FB
C++
FB versus C++
Itanium C++ ABI (http://itanium-cxx-abi.github.io/cxx-abi/abi.html)
Builtin types single-letter codes:
a := signed char
h := unsigned char
s := short
t := unsigned short
i := int
j := unsigned int
l := long
m := unsigned long
x := long long, __int64
y := unsigned long long, __int64
With this change, match up FB to C++ ABI, depends on platform and other compiler (gcc)
Shown in next list is 1) platform, 2) C++ sizes of unsigned char, short, int, long, long long,
3) name mangling suffix for a comparible type in FB
Some popular targets:
linux 32-bit: 1 <= 2 <= 4 <= 4 <= 8, asilx
linux 64-bit: 1 <= 2 <= 4 <= 8 <= 8, asilx
windows 32-bit: 1 <= 2 <= 4 <= 4 <= 8, asilx
windows 64-bit: 1 <= 2 <= 4 <= 4 <= 8, asi?x
Problems in EXTERN "C++":
Possibly solutions to Win64 & EXTERN "C++"
This last possible solution might be worth exploring. It fits with our notion that FB INTEGER size is dependant on platform.
I tried some of the ideas I mentioned in last post:
I created a pull request for an extension of dkl/integer-mangling that works as follows:
Not directly related, but is also mangling, there is a fix for [#890] in the pull request.
Related
Bugs:
#890The specific bug reported "32bit Integer/Long mangling reversed" fixed in commit: [90f331]
'long alias "long"' added in commit: [e07d3b]
note add to wiki at Alias
Related
Commit: [90f331]
Commit: [e07d3b]