[CMake] PIE and PIC in mixed projects

Ryan Pavlik rpavlik at iastate.edu
Thu Sep 9 08:09:54 EDT 2010


Not sure how you're setting the LDFLAGS, but if you append -fPIE -pie to
this variable, it should be used only for executables.

http://cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_EXE_LINKER_FLAGS

There is an undocumented peer to this variable, something like
CMAKE_LIBRARY_LINKER_FLAGS, (search the mailing list archives - someone
replied to a message from me within the last month and named that variable)
which you may consider modifying through a search/replace to remove -fPIE
and -pie.

Ryan

On Thu, Sep 9, 2010 at 6:58 AM, Emil Langrock <emil.langrock at gmx.de> wrote:

> Hi,
>
> I have a project which builds shared objects and executables on linux. The
> goal is to have the library as PIC and the executable as PIE. PIC seems not
> a
> problem as cmake already does it.
>
> There exist a blacklist for architectures which doesn't support PIE well
> yet
> (hppa, m68k, mips, mipsel, avr32). This list is managed by the distribution
> and thus the distribution gives the pie information via C(XX|PP)FLAGS to
> cmake.
>
> In case of a platform with pie support, we would have following flags set:
>
> CFLAGS  := -fPIE
> LDFLAGS := -fPIE -pie
>
>
> The problem is now that the library cannot have the LDFLAGS -fPIE -pie and
> CFLAGS -fPIE set as it is a PIC and not a PIE.
>
> As result cmake does something like (a little bit simplified):
> $ echo 'void test(void) {} void bla(void) { test(); }' > test.c
> $ gcc -fPIE -pie -fPIC test.c -shared -o test.so
> /usr/bin/ld.bfd.real: /tmp/cc7oYMnf.o: relocation R_X86_64_PC32 against
> symbol
> `test' can not be used when making a shared object; recompile with -fPIC
> /usr/bin/ld.bfd.real: final link failed: Bad value
> collect2: ld returned 1 exit status
>
> My first tests with libtool (via autotools project) worked fine. The reason
> seems to be that libtool is intelligent enough detect that pie is not for
> shared objects and strips it for the compilation and linking process for
> them.
>
> So my question: How is a similar functionality with cmake possible?
>
> Example project is amarok.
> --
> Emil Langrock
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

rpavlik at iastate.edu
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100909/18be519c/attachment.htm>


More information about the CMake mailing list