-
-
Notifications
You must be signed in to change notification settings - Fork 904
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
Compile native extensions with '-O2 -g' flags #2100
Compile native extensions with '-O2 -g' flags #2100
Conversation
Code Climate has analyzed commit abd5669 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (80% is the threshold). This pull request will bring the total coverage in the repository to 94.3% (0.0% change). View more on Code Climate. |
✅ Build nokogiri 1.0.712 completed (commit 6f7a4458b0 by @ilyazub) |
Thank you for submitting this! Looks good, will likely merge this weekend and ship in the next v1.11.0 release candidate. |
Fascinating! When compiled with
I'll try to take a look over the weekend. |
Threw it into a debugger and here's a partial stack walkback:
So it looks like this is segfaulting on a |
because this makes the precompiled (glibc) library segfault on musl. Related to a3d9438 and sparklemotion#2022
This seems to be related to:
So I've pushed an additional commit that turns this macro off, and musl seems to now work. Let's watch what CI says ... EDIT: CI went green For context, here's a thing that explains _FORTIFY_SOURCE pretty well: https://p0lycarp.github.io/2019/fortify/ And here's some context around musl support for it: |
✅ Build nokogiri 1.0.713 completed (commit 7faad5c213 by @flavorjones) |
Where is it defined that I've modified example code from blog post on #include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
#ifdef _FORTIFY_SOURCE
printf("_FORTIFY_SOURCE defined\n");
#endif
char buf[5];
strcpy(buf, argv[1]);
puts(buf);
} The output shows that
Checked with $ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20200723 (Red Hat 10.2.1-1) (GCC) |
From
|
Oh, I see.
Output from
|
Is it okay to turn off |
@ilyazub I'm not sure what you're asking when you say "all native extensions." In the particular case of libxml2 and #2022 I think it's safe:
If you have reason to think this is unsafe, please let me know. |
Oh, if your question was about using _FORTIFY_SOURCE=0 for all the libraries, you're correct that this PR is adding the CFLAGS in the wrong place; but it's difficult to add them in the right place because of the way |
Yes, I mean diff --git a/ext/nokogiri/extconf.rb b/ext/nokogiri/extconf.rb
index 89c6ec56..030cfb92 100644
--- a/ext/nokogiri/extconf.rb
+++ b/ext/nokogiri/extconf.rb
@@ -582,7 +582,8 @@ EOM
"--with-c14n",
"--with-debug",
"--with-threads",
- *(darwin? ? ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"] : "")
+ *(darwin? ? ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"] : ""),
+ "CFLAGS=-O2 -U_FORTIFY_SOURCE -g"
]
end |
@flavorjones Thanks for convincing me that it's safe. I'm asking about the safety of this change because I have almost no experience in C. |
✅ Build nokogiri 1.0.714 completed (commit 0dd73c4e8c by @flavorjones) |
This is the default for those libraries, but we were overriding CFLAGS in some cases. Additionally, we need to compile with -U_FORTIFY_SOURCE to avoid Ubuntu's convention of setting -D_FORTIFY_SOURCE=2 when -O2 is set. This leads to problems when running precompiled libraries on musl (see #2100 for details). Closes #2022.
@flavorjones Thank you! |
Resolves #2022.
In my case parsing of a big HTML file decreased from 1.1 seconds to 210 ms.
@flavorjones Regarding the final challenge, I haven't cleaned up
process_recipe
andconfigure_options
, but I can try if you add some guidance or vision of the result.And thanks for the detailed issue description. It was pretty straightforward to make this change.