C/C++ linker CALL16 reloc at xxxxx not against glo

2019-02-19 00:05发布

问题:

I'm getting these errors while linking, both messages have to do with the same object file.

CALL16 reloc at 0x5f8 not against global symbol

and

could not read symbols: Bad value

The 2nd message seems to be the reason I'm getting the CALL16 error, but the file compiles just fine.

Any tips on fixing this?

FYI, I'm cross compiling for a MIPS target and using gcc 4.1.2

EDIT: No luck so far:
Here are my flags used: -fPIC,-Wl,-rpath,-Wl,-O1

I've also tried the following without success:
-mno-explicit-relocs
-mexplicit-relocs
-mlong-calls
-mno-long-calls
-mxgot
-mno-xgot


Meanwhile, I'll go back to the source at this point and investigate more.

回答1:

Aha! Thanks to a colleague of mine, we found the issue.

Here was the issue:

There was a forward declaration/prototype of a function.

void FooBarIsBest(void);

Later on in the file the function was defined.

static void FooBarIsBest(void)
{
    // do the best
} 

The issue here was that in the prototype the keyword static was left out. So it was like a whole new function was being defined.

The CALL16 reference is used by gcc for relocatable code. The assembly code of the file showed that CALL16 was being used on this function... Which is wrong, as this function is local.

Interestingly, this code used to compile & link just fine with an older version of gcc (3.2.2). Another lessoned learned. :)



回答2:

Try -mlong-calls flag to the compiler.

Also see the manual for more specific MIPS options.