[gmp | mpir] Add --with-pic#25209
Conversation
There was a problem hiding this comment.
You have modified or added at least one vcpkg.json where you should check the license field.
Details
If you feel able to do so, please consider adding a "license" field to the following files:
ports/gmp/vcpkg.json
Valid values for the license field can be found in the documentation
|
I added a line to the description describing why this isn't the typical "the toolchain should handle that" case :). |
|
|
||
| if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") | ||
| set(SHARED_STATIC "--enable-static --disable-shared") | ||
| set(SHARED_STATIC --enable-static --disable-shared --with-pic) |
There was a problem hiding this comment.
Hmmm... usually it's dynamic libs that need PIC, not static. Are you sure you didn't flip the sense here?
There was a problem hiding this comment.
For non-Windows systems, dynamic libraries require position independent code (aka PIC). On Linux, vcpkg default toolchain, on x86_64, uses static libraries by default:
vcpkg/triplets/x64-linux.cmake
Lines 1 to 5 in 8e1f46d
But toolchain adds -fPIC as well:
vcpkg/scripts/toolchains/linux.cmake
Lines 51 to 52 in 8e1f46d
That means that static libraries will be created, but with position independent code inside. That allows to link those static libraries to shared libraries.
The issue #13827 is a bug with GMP or MPIR, because GMP and MPIR have assembler code, to speed-up critical algorithms. That is why GMP and MPIR needs the macro PIC defined (with -DPIC, or with the option --with-pic to ./configure).
There was a problem hiding this comment.
PIC is already the default for shared libraries. We can add the option --with-pic:
- only to static builds, like in MPIR port file,
- or to any kind of build, like in GMP port file,
and that will have the same behavior: both static and dynamic builds will have PIC code.
There was a problem hiding this comment.
Makes sense 👍. Should we add a comment or something indicating that?
There was a problem hiding this comment.
I was told that it is a concious decision that vcpkg always uses PIC, even for static triplets, to allow mixing of static and shared libs. It doesn't need to be documented per port. If there is a need to add a comment, it should be in a central location.
There was a problem hiding this comment.
@dg0yt I don't mean that overall consistency decision, I mean something like:
# Add --with-pic even in static for consistency with vcpkg's toolchain.
# Note that this is necessary for GMP's `-DPIC` rather than `-fPIC`.
There was a problem hiding this comment.
(To be clear, I'm not saying "please do this", I'm saying "have you considered doing this to stop people's eyebrows from being raised" @lrineau )
Describe the pull request
What does your PR fix?
Fixes [MPIR:x64-linux] build failure (static linking) #13827.
Adding
-fPICis normally handled by the toolchain. However, GMP and MPIR need their own specific define-DPIC.See also the other attempt at [vcpkg-tool] Add -DPIC to pic flags on Linux #25158.
Which triplets are supported/not supported? Have you updated the CI baseline?
all
Does your PR follow the maintainer guide?
Yes, I think so.
If you have added/updated a port: Have you run
./vcpkg x-add-version --alland committed the result?Yes.