New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS: Prevent Xcode 9.3 build warnings #12899
macOS: Prevent Xcode 9.3 build warnings #12899
Conversation
utACK. It looks like |
Nice! Tested ACK. |
configure.ac
Outdated
@@ -633,7 +633,7 @@ if test x$use_hardening != xno; then | |||
|
|||
if test x$TARGET_OS != xwindows; then | |||
AX_CHECK_COMPILE_FLAG([-fPIE],[PIE_FLAGS="-fPIE"]) | |||
AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"]) | |||
AX_CHECK_LINK_FLAG([[-Wl,-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-pie"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this also correct for non-macOS? I've seen -pie
a lot in build systems but never -Wl,-pie
.
@theuni?
(see edit at bottom) The issue here is that macOS is always pie, so there's no need to specify it. The compiler front-end warns about it, but I guess the linker doesn't care. @kallewoof default-pie is a configure option for recent compilers (at least for gcc, and I assume clang as well). It's up to distros/packagers whether they want to enable it or not. Modern distros have begun enabling it. So the change here doesn't really fix the problem, it just bypasses the compiler and goes straight to the linker, which may also start complaining in some future version. What we should be doing here is checking for warnings in the test instead. Windows is also default-pie and was special-cased because it also warned, but we can also eliminate that case if warnings are caught: AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"])
AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"])
- if test x$TARGET_OS != xwindows; then
- AX_CHECK_COMPILE_FLAG([-fPIE],[PIE_FLAGS="-fPIE"])
- AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"])
- fi
+ AX_CHECK_COMPILE_FLAG([-fPIE],[PIE_FLAGS="-fPIE"], [[$CXXFLAG_WERROR]]))
+ AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [[$CXXFLAG_WERROR]])
case $host in
*mingw*) As for libbitcoinconsensus, building it as pie is the wrong thing to be doing anyway. I'm actually not sure how that's working now. I believe the proper fix is simply: diff --git a/src/Makefile.am b/src/Makefile.am
index 993bf20387..b5f8b2c197 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -457,7 +457,7 @@ endif
libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1)
libbitcoinconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL
-libbitcoinconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
+libbitcoinconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIC_FLAGS)
endif
# Edit: On second glance, libbitcoinconsensus will still end up with -pie on linux because AM_LDFLAGS contains HARDENED_LDFLAGS. I guess we'll need to split pie out of HARDENED_LDFLAGS :( Edit2: Researching this for what must be the hundredth time and it's just as hazy as ever. It looks like building the lib as -pie might be fine, but it'd be nice to find a definitive answer and add a comment with an explanation. If that's the case, the second patch here can just be dropped. |
@theuni Thank you for your review. |
@theuni Thanks for the detailed explanation! I agree that we should check for pie warnings as in your first patch. No idea on the second patch, really. |
@theuni I understood that how to use 4th parameter of AX_CHECK_{COMPILE,LINK}_FLAG(). |
@kallewoof I think the first patch is enough to fix the warnings reported by @AkioNak, and the second patch (building a shared lib as pie) can actually be dropped here as it is a separate concern. @AkioNak Could you try that and see if it works for you? |
@theuni sure. I will try it soon. |
12ebae7
to
6c10035
Compare
@theuni @kallewoof fixed and rebased to master 727175a. But Travis-Job #27212.2 and #27212.5 have failed at |
Fixes my Xcode 9.3 maxOS 10.12 compiler warnings. |
Also tested that 6c10035 fixes all It seems like we don't have a clear conclusion on the second patch? We should open an issue to track that if required. |
Thanks! utACK 6c1003589919b77dc9b143b4851cb123869b8fd0. Test failure seems unrelated, I'll restart it. @fanquake Yes, it's not actually all that related here, since the new changes take care of the issue with libbitcoinconsensus also. And it's clearly not a real-world issue at the moment that we're building the library with -pie, as it seems to work fine. It'd be nice to find some real guidance, though, so that we at least know if it's just accidentally working. |
The travis failure in Edit: see issue #12955 |
ok, seems this is a genuine problem. @AkioNak: Sorry that this got off-track.
A quick look around the net points out plenty of issues with mingw and pie.
I think we can eliminate the possibility with a combined check:
|
This PR solves bitcoin#12867 (needs to run autogen.sh && ./configure) clang (Apple LLVM version 9.1.0 (clang-902.0.39.1)) warns unused argument '-pie' during compilation. So we check for warnings in the test using $CXXFLAG_WERROR. Windows is alse default-pie and was special-cased because it also warned, but we can also eliminate that case if warnings are caught.
6c10035
to
2eb5036
Compare
@theuni thanks. fixed and rebased. |
Thanks. utACK.
|
macOS 10.13.4 Compiling master (e76acf3):
Compiling (2eb5036):
No -pie related compilation warnings |
Tested ACK 2eb5036 |
2eb5036 macOS: Prevent Xcode 9.3 build warnings (Akio Nakamura) Pull request description: This PR intends to solve #12867 1. clang (Apple LLVM version 9.1.0 (clang-902.0.39.1)) warns unused argument '-pie' during compilation. This parameter should pass to the linker, so use '-Wl,-pie' style in configure.ac. 2. The other hand, when linking libbitcoinconsensus.la with passing '-Wl,-pie', ld warns that '-pie' being ignored because not link a main executable. So remove it from $libbitcoinconsensus_la_LDFLAGS in src/Makefile.am. - In order to apply this change to Makefile, you need to run autogen.sh and ./configure. - I think no need to add if-clause by target-os because also g++ can recognize/handle '-Wl,-pie'. - I confirmed that the build was successful on macos10.13.4/XCode9.3 and ubuntu 17.10/g++7.2.0 and that warning was not issued. Tree-SHA512: 45b7c3881f3ad92172eb2ff6fa90c4dc70a42037450ea4b6fd87613b10c0aa90ebcffd54e7c50b70ba876b7c2e356825950fbf5a7a4e8e25118688d98d7b6ee0
2eb5036 macOS: Prevent Xcode 9.3 build warnings (Akio Nakamura) Pull request description: This PR intends to solve bitcoin#12867 1. clang (Apple LLVM version 9.1.0 (clang-902.0.39.1)) warns unused argument '-pie' during compilation. This parameter should pass to the linker, so use '-Wl,-pie' style in configure.ac. 2. The other hand, when linking libbitcoinconsensus.la with passing '-Wl,-pie', ld warns that '-pie' being ignored because not link a main executable. So remove it from $libbitcoinconsensus_la_LDFLAGS in src/Makefile.am. - In order to apply this change to Makefile, you need to run autogen.sh and ./configure. - I think no need to add if-clause by target-os because also g++ can recognize/handle '-Wl,-pie'. - I confirmed that the build was successful on macos10.13.4/XCode9.3 and ubuntu 17.10/g++7.2.0 and that warning was not issued. Tree-SHA512: 45b7c3881f3ad92172eb2ff6fa90c4dc70a42037450ea4b6fd87613b10c0aa90ebcffd54e7c50b70ba876b7c2e356825950fbf5a7a4e8e25118688d98d7b6ee0
2eb5036 macOS: Prevent Xcode 9.3 build warnings (Akio Nakamura) Pull request description: This PR intends to solve bitcoin#12867 1. clang (Apple LLVM version 9.1.0 (clang-902.0.39.1)) warns unused argument '-pie' during compilation. This parameter should pass to the linker, so use '-Wl,-pie' style in configure.ac. 2. The other hand, when linking libbitcoinconsensus.la with passing '-Wl,-pie', ld warns that '-pie' being ignored because not link a main executable. So remove it from $libbitcoinconsensus_la_LDFLAGS in src/Makefile.am. - In order to apply this change to Makefile, you need to run autogen.sh and ./configure. - I think no need to add if-clause by target-os because also g++ can recognize/handle '-Wl,-pie'. - I confirmed that the build was successful on macos10.13.4/XCode9.3 and ubuntu 17.10/g++7.2.0 and that warning was not issued. Tree-SHA512: 45b7c3881f3ad92172eb2ff6fa90c4dc70a42037450ea4b6fd87613b10c0aa90ebcffd54e7c50b70ba876b7c2e356825950fbf5a7a4e8e25118688d98d7b6ee0
2eb5036 macOS: Prevent Xcode 9.3 build warnings (Akio Nakamura) Pull request description: This PR intends to solve bitcoin#12867 1. clang (Apple LLVM version 9.1.0 (clang-902.0.39.1)) warns unused argument '-pie' during compilation. This parameter should pass to the linker, so use '-Wl,-pie' style in configure.ac. 2. The other hand, when linking libbitcoinconsensus.la with passing '-Wl,-pie', ld warns that '-pie' being ignored because not link a main executable. So remove it from $libbitcoinconsensus_la_LDFLAGS in src/Makefile.am. - In order to apply this change to Makefile, you need to run autogen.sh and ./configure. - I think no need to add if-clause by target-os because also g++ can recognize/handle '-Wl,-pie'. - I confirmed that the build was successful on macos10.13.4/XCode9.3 and ubuntu 17.10/g++7.2.0 and that warning was not issued. Tree-SHA512: 45b7c3881f3ad92172eb2ff6fa90c4dc70a42037450ea4b6fd87613b10c0aa90ebcffd54e7c50b70ba876b7c2e356825950fbf5a7a4e8e25118688d98d7b6ee0
This PR intends to solve #12867