Hello there.
For a project I am trying to build an elf relocatable binary that has no PLT/GOT and relies purely on relocations. I’m aware that this can be archived in gcc (possibly with -mcmodel=large
).
However the generator always appends -fPIC
to the link commands, no matter if POSITION_INDEPENDENT_CODE
is set to False not.
This happens with both gnu make and ninja. My current (temporary) solution to this problem is to sed replace -fPIC
in the generator files.
Here is a quick MRE:
- CMakeList.txt
add_library(test SHARED test.c)
set_target_properties(test
PROPERTIES
POSITION_INDEPENDENT_CODE False
)
When running this with cmake -G "Unix Makefiles"
this produces the following:
- CMakeFiles/test.dir/link.txt:1
/usr/lib64/ccache/cc -fPIC -shared -Wl,-soname,libtest.so -o libtest.so CMakeFiles/test.dir/test.o
When running with cmake -G "Ninja"
instead it produces something simmilar:
- MakeFiles/rules.ninja:28
command = $PRE_LINK && /usr/lib64/ccache/cc -fPIC $LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS $LINK_FLAGS -shared $SONAME_FLAG$SONAME -o $TARGET_FILE $in $LINK_PATH $LINK_LIBRARIES && $POST_BUILD
I am not sure if this is a bug or a mistake on my part.
I appreciate any help with this!