gcc -flto undefined reference errors

132 Views Asked by At

Recently I tried using link time optimization but didn't get very far. On the first attempt to link an exe I get a load of

{path}/bin/ld: <artificial>:(.text.startup+0x136): undefined reference to `some_function`

errors.

I can't see anything much special about the functions. We do take their addresses, and also refer to them via macros.

This is on RHEL 7.6 home rolled GCC 5.3 and binutils 2.34 (I don't know how they were configured unfortunately).

For a non-lto build I see that one of the functions is in a read-onlu section (according to nm). I see the same symbol in a .a file. From that I can find the .o file.

Going back to the lto version, with objdump -D I see

.gnu.lto_{missing function}.7c974f7d7bc920e2

And that's about as far as I can get. My only idea is that this is some sort of ODR violation that doesn't show up otherwise.

EDIT: I've made some progress. Some if not all of the symbols are in .rodata arrays of pointers to functions.

These are generated in multiple files using some nasty C macros, something like this:

// file1.c
#include "param1_def.h"
#include "pfn_table.c"
// file2.c
#include "param2_def.h"
#include "pfn_table.c"

and

// pfn_table.c
function_type const MAKE_NAME(NAME, _functions) =
{
   MAKE_NAME(NAME, _write_file),
   MAKE_NAME(NAME, _read_file),
   // etc
}

Where NAME is a macro defined in the paramX_def.h headers (and is different each time) and MAKE_NAME is a macro that pastes together the final names.

0

There are 0 best solutions below