My project have a several object files with project internal functions, and one object file which exposes functions for a public interface. My goal is to use incremental linking to combine all object files to a single file, and have this single file only expose the symbols needed for the public interface.
foo.c, public interface.
void bar(void);
void foo(void)
{
bar();
}
bar.c, project internal function.
void bar(void)
{
}
$ gcc -c foo.c
$ gcc -c bar.c
$ ld -r -o combined.o foo.o bar.o
$ strip -N bar combined.o
strip: not stripping symbol `bar' because it is named in a relocation
Both functions are already part of the same segment in the same object file, so I believe it should be possible to resolve the relocation during the link step? Is it possible to alter the ld
command in order for the relocation not to be needed?