Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rename a symbol using a linker script

Is it possible to use a linker script or mapfile to rename a symbol? I'm trying to adapt some code written in a mix of C++ and Fortran so that it will work with more than one Fortran compiler - on Linux. It is currently written for the Solaris Studio compiler with the option for case-sensitivity enabled. I'd like to handle variations in Fortran symbol name mangling automatically (such as from the Makefile).

It does appear to be possible to create aliases so, a linker script containing:

C_Function_ = c_function;

will sort-of work. Unfortunately, adding the -T option to reference this script causes some other change in behaviour and I get errors due to libdl.so.2/librt.so.1 not being found. Is there some sort of default linker script that I need to include or something? I've tried with both bfd and gold linkers on Linux.

like image 528
okapi Avatar asked Mar 10 '23 00:03

okapi


1 Answers

You cannot really rename symbols, but you can define aliases to existing symbols like

PROVIDE(c_function = C_function_);
...

in a linker script.

If you pass this linker script with the -T option to ld, it will replace the original (default) linker script. If you rather want to have the linker script extend the default, pass it without the -T option (just like you would with an additional object file).

This way, everything should work as expected.

like image 113
mfro Avatar answered Mar 20 '23 08:03

mfro