4

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.

okapi
  • 1,340
  • 9
  • 17

1 Answers1

7

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.

mfro
  • 3,286
  • 1
  • 19
  • 28
  • Thanks, omitting the `-T` solves this. What does the `PROVIDE` do? That prevents it working for the case where the symbol is compiled into a shared library. – okapi Feb 13 '17 at 15:53
  • `PROVIDE()` ensures the symbol is only aliased if the name used doesn't already exist. Not sure why this should collide with building a shared library, though. – mfro Feb 13 '17 at 16:43
  • I have a situation where two libraries--SystemC and Catch2--both provide a main function, and I'd like to override the SystemC main so that the program entry starts with Catch2's main and allows me to call the SystemC main. Is it possible to use aliases for this? – sheridp Dec 13 '18 at 17:00
  • @sheridp: I'd say no. This is another problem that deserves its own question – mfro Jan 19 '19 at 18:56