[libcxx-commits] [PATCH] D104328: [libc++] Always build libc++ and libc++abi with -fPIC

Chandler Carruth via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 26 15:09:20 PDT 2021


chandlerc added a comment.

FWIW, I think this patch makes sense to me.

Even if we start building releases with PIC, I think the static *runtimes* would still benefit from being explicitly PIC. Some users may reasonably disable PIC for the overall build but for runtime libraries specifically it seems desirable for them to support the static archive being linked into a DSO where PIC is required.



================
Comment at: libcxx/src/CMakeLists.txt:276
       OUTPUT_NAME   "c++"
+      POSITION_INDEPENDENT_CODE ON
   )
----------------
ldionne wrote:
> compnerd wrote:
> > Why build the static library as PIC?  It is going to be statically linked so it doesn't really need to be position independent.  Even if you were to statically link the library into a shared library, it would basically be fully internalized, and the linker should be able to lay it out so that you don't need the PLT/GOT indirection.
> This is precisely what the bug report here is asking for: http://llvm.org/PR43604
> 
> In fact, this patch builds the shared library with `fPIC` mostly for consistency with the static library. I think it would be useful to have a discussion with the reporter of that bug, and I also know @chandlerc cares about this use case.
> 
> Basically, I'm willing to apply whatever fix is going to make people happy, but I'm not sure what's the correct fix here - I'm a bit out of my depth.
Just to be clear -- I don't know how to build a `.a` file w/o PIC code and link it into a `.so` that is PIC... Even though it wouldn't need PLT/GOT indirection, the basic references would need to be IP/PC relative to support the outer `.so` being PIC... At least, as far as I know.

As long as we want runtime `.a`s to be linked into user `.so`s, forcing PIC seems like the only realistic path.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104328/new/

https://reviews.llvm.org/D104328



More information about the libcxx-commits mailing list