How to use decimal floating point in Gnu C++ (g++)? - c++

GCC 4.5 added support for decimal floating points in the runtime library (http://gcc.gnu.org/gcc-4.5/changes.html). I'm able to compile code including , using namespace std::decimal, then using decimal64 and so on in the code.
Unfortunately, I'm missing some library for linking the code. I've not been able to find out which libraries should be required. DFP support is enabled in gcc (--enable-decimal-float=dpd)
Additionally, should there be some fast way of providing decimal literals in the code? By fast, I mean user defined literals that are handled by templates and translated at compile time. I do not want to provide doubles that are converted at runtime (despite performance and the fact that I really can't stand moving evaluations from compile time to runtime there are still rounding issues...). I've already found the suffix "df" but that does not seem to be recognized by the compiler.
I'm using gcc version 4.7.1 on target powerpc-ibm-aix7.1.0.0.
Linker error messages:
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatsisd
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatsidd
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatsitd
ld: 0711-317 ERROR: Undefined symbol: .__dpd_mulsd3
ld: 0711-317 ERROR: Undefined symbol: .__dpd_muldd3
ld: 0711-317 ERROR: Undefined symbol: .__dpd_multd3
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatdisd
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatunsdisd
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatdidd
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatunsdidd
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatditd
ld: 0711-317 ERROR: Undefined symbol: .__dpd_floatunsditd
TIA.

I've recently compiled gcc4.7.1 from source and had trouble with missing symbol __floatunsidf. This turned out to be a symbol required by libstdc++.so and defined in libgcc_s.so. Given that both Libraries are provided by gcc they should be compatible. In my case i still had a linker include to an old version of libgcc_s that i'd lifted from my target platform. Its probably worth doing
# to find out where libstdc++.so is:
gcc -print-file-name=libstdc++.so
# see if it references the symbol you're missing
readelf -a "path to libstdc++.so" | grep "symbol name"
and then doing the same for libgcc_s to see if they both define the symbol you are missing. Nb one will mark the symbol as undefined - thats how the linker knows its required.

Related

GRPC cross compile for android using NDK toolchain

I am fairly new to this. So, I am trying to cross compile GRPC (https://github.com/grpc/grpc) for android using cmake and NDK toolchain to generate shared libraries, using the below:
cmake -DCMAKE_TOOLCHAIN_FILE=$And_PATH/android.toolchain.cmake -DCMAKE_CROSSCOMPILING=true -DANDROID_ABI=arm64-v8a -DCMAKE_INSTALL_PREFIX=/cross_grpc -DANDROID_PLATFORM=android-26 -DANDROID_STL=c++_shared CFLAGS="std=c11" CXXFLAGS="std=c++14" cmake -B . -S /grpc
With the above i am able to build and static libraries get generated, but if i add -DBUILD_SHARED_LIBS=ON , i am getting below errors
ld: error: undefined symbol: BIO_ctrl
referenced by bio_ssl.cc:191 (/grpc/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc:191)
ld: error: undefined symbol: BIO_clear_retry_flags
referenced by bio_ssl.cc:65 (/grpc/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc:65)
ld: error: undefined symbol: BIO_set_retry_write
referenced by bio_ssl.cc:71 (/grpc/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc:71)
I have not pasted all the errors as it's a long list of undefined symbol errors.

Define a global in linux kernel but link failed

I'm doing some experiments on linux kernel, I add two global variables in init/main.c shown below.
#define CODE_COUNT 1100
unsigned code_counter[ASM_CODE_COUNT];
unsigned code_counter_overflow[ASM_CODE_COUNT];
EXPORT_SYMBOL(code_counter);
EXPORT_SYMBOL(code_counter_overflow);
After this I want to use them in other files, but I got the following error:
ld: arch/x86/entry/vdso/vgetcpu.o: in function `vdso_read_cpunode':
linux-5.17.2/./arch/x86/include/asm/segment.h:255: undefined reference to `code_counter'
ld:linux-5.17.2/./arch/x86/include/asm/segment.h:255: undefined reference to `code_counter_overflow'
objdump: 'arch/x86/entry/vdso/vdso64.so.dbg': No such file
ld: arch/x86/entry/vdso/vgetcpu-x32.o: relocation R_X86_64_PC32 against undefined symbol `code_counter' can not be used when making a shared object; recompile with -fPIC
ld: final link failed: bad value
I add extern unsigned code_counter[] extern unsigned code_counter_overflow[] to these files.

Undefined symbol vs undefined reference

I saw this post here: ld: undefined symbol vs ld: undefined reference and I don't think it really talks about what the differences are between these 2 linker errors.
I usually get undefined reference linker errors when the linker can't find the definition of something (or I declared it and forgot to define it), but it seems undefined symbol serves the same purpose (the answer in the above linked post gives an example that seems to be aligned with when undefined reference arises, but maybe I'm missing some subtlety here?), so I'm a bit confused. Can someone clarify, perhaps with examples, of when each one arises during linking?
Edit: I didn't know the terminology for linker errors could be dependent on if using gnu, clang, etc...
In my case, I saw the undefined symbol error when using clang++ and the error was
stderr: ld.lld: error: undefined symbol: custom::linear::adapt()
Is undefined symbol the clang counterpart to gnu's undefined reference?

Timersub and timeradd on AIX

I'm fairly new to the AIX platform. Currently porting an application from linux to AIX.
I know timeradd and timersub aren't supported on AIX which is why I get the following error:
ld: 0711-317 ERROR: Undefined symbol: .timeradd
ld 0711-317 ERROR: Undefined symbol: .timersub
ld 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
Is there a workaround? Or a patch for the definitions?

Using 32-bit g++ to build 64-bit binaries on AIX

I am trying to build a 64-bit binary from C++ code using 32-bit g++ compiler.
I am getting the following errors while building:
=> /usr/local/bin/g++ -shared -maix64 -fPIC -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bE:gcc_shr_lib.so.exp -o gcc_shr_lib.so gcc_shr_lib.o -L/usr/local/lib
ld: 0711-319 WARNING: Exported symbol not defined: gcc_whereAmI
ld: 0711-317 ERROR: Undefined symbol: typeinfo for std::bad_alloc
ld: 0711-317 ERROR: Undefined symbol: __gxx_personality_v0
ld: 0711-317 ERROR: Undefined symbol: vtable for std::exception
ld: 0711-317 ERROR: Undefined symbol: vtable for std::bad_alloc
ld: 0711-317 ERROR: Undefined symbol: .std::ios_base::Init::Init()
ld: 0711-317 ERROR: Undefined symbol: .std::ios_base::Init::~Init()
ld: 0711-317 ERROR: Undefined symbol: .operator new(unsigned long)
ld: 0711-317 ERROR: Undefined symbol: .operator delete(void*)
ld: 0711-317 ERROR: Undefined symbol: ._Unwind_Resume
ld: 0711-317 ERROR: Undefined symbol: .__cxa_get_exception_ptr
ld: 0711-317 ERROR: Undefined symbol: .__cxa_begin_catch
ld: 0711-317 ERROR: Undefined symbol: std::cout
ld: 0711-317 ERROR: Undefined symbol: .std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
ld: 0711-317 ERROR: Undefined symbol: std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
ld: 0711-317 ERROR: Undefined symbol: .std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
ld: 0711-317 ERROR: Undefined symbol: .std::bad_alloc::~bad_alloc()
ld: 0711-317 ERROR: Undefined symbol: .__cxa_end_catch
ld: 0711-317 ERROR: Undefined symbol: .__register_frame_info_table
ld: 0711-317 ERROR: Undefined symbol: .__deregister_frame_info
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: ld returned 8 exit status
It seems I need 64-bit libstdc++ available on my build system. Could someone please throw some light on to solve this?
Is it OK to build 64-bit binaries using 32-bit g++ compiler on AIX 5.2?
Where should I get 64-bit libstdc++? Will this 64 bit libstdc++ work with 32-bit g++ compiler?
Thanks a lot for your quick response and for pointing out the problem.
Following are the versions of GCC/G++ I am using:
=> gcc -v
Using built-in specs.
Target: powerpc-ibm-aix5.2.0.0
Configured with: ../gcc-4.1.1/configure --disable-aix64 --disable-nls
Thread model: aix
gcc version 4.1.1
[tsivaram#maroon /]
=> g++ -v
Using built-in specs.
Target: powerpc-ibm-aix5.2.0.0
Configured with: ../gcc-4.1.1/configure --disable-aix64 --disable-nls
Thread model: aix
gcc version 4.1.1
Since gcc and g++ are configured/built with --disable-aix64, there are no 64-bit STD libraries available (Ex: libstdc++).
AIX version i am using:
=> uname -a
AIX maroon 2 5 000663FC4C00
[tsivaram#maroon /]
=> oslevel
5.2.0.0
[tsivaram#maroon /]
=> oslevel -r
5200-05
How can I build 64-bit libstdc++, which should work with gcc/g++ 4.1.1?
Do I need to rebuild GCC and G++ without the --disable-aix64 flag? If yes, could you please point to me a link explaining how to build?
Can not we just build libstdc++ library (required)?
You seem to be building a shared library rather than an executable.
As long as the relevant 64-bit libraries are available on the machine, it should not matter whether your G++ is itself a 32-bit or a 64-bit binary - it should be able to generate both 32-bit and 64-bit object files (and shared libraries, and executables, etc).
Be aware that GCC (or G++) uses a different name-mangling scheme from other compilers quite deliberately - because it does various things (such as exception handling, class layouts and the like) differently from other compilers. You cannot reliably link code compiled with the native XLC compilers with code compiled with G++. However, you do not seem to be doing that here.
You should look under /usr/local/lib to see what you can find in the way of 64-bit C++ libraries; you may need to mention the right directory and shared library name on the command line. Alternatively, add the '-v' flag to the command and see what is actually being executed.
You seem to just have missing symbols; you don't have mismatched 32-bit vs 64-bit object files or libraries or whatever. So, you're close - just not quite there yet.
(Is AIX 5.2 still supported? Shouldn't you be planning to move to 5.3 or 6.1?)