Skip to content
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

Disable -fPIE for HiPE on x86_64 #1239

Merged
merged 2 commits into from
Nov 11, 2016

Conversation

sverker
Copy link
Contributor

@sverker sverker commented Nov 8, 2016

This is an attempt to fix https://bugs.erlang.org/browse/ERL-294
by letting configure disable position independent executable (PIE) if

  • PIE is enabled by default
  • and hipe is enabled
  • and architecture is x86_64 (amd64)

I encourage stake holders to test this before we merge into maint for OTP-19.2.

@@ -2771,6 +2771,21 @@ if test "$cross_compiling" != "yes" && test X${enable_hipe} != Xno; then
fi
fi

dnl Check to disable -fPIE and friends for HiPE on amd64
if test X${enable_hipe} = Xyes && test X$ARCH = Xamd64; then
AC_TRY_COMPILE(, [#ifdef defined(__pie__) || defined(__PIE__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work, #ifdef should be changed to #if.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
Believe it or not but I actually tested both branches of AC_TRY_COMPILE.
#ifdef define(..) succeeded with just a warning "extra tokens at end of #ifdef directive" (that I never saw).
Then I changed it to !defined(..) and that did not compile as expected.

@weisslj
Copy link
Contributor

weisslj commented Nov 8, 2016

This does not work for me with the Debian gcc-6 compiler:

 MAKE   depend
make[1]: Entering directory '/home/weisslj/src/otp/erts/emulator'
 MAKE   generate
make[2]: Entering directory '/home/weisslj/src/otp/erts/emulator'
 GEN    x86_64-unknown-linux-gnu/gen_git_version.mk
 LD /home/weisslj/src/otp/bin/x86_64-unknown-linux-gnu/hipe_mkliterals
/usr/bin/ld: obj/x86_64-unknown-linux-gnu/opt/plain/hipe_mkliterals.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
x86_64-unknown-linux-gnu/Makefile:934: recipe for target '/home/weisslj/src/otp/bin/x86_64-unknown-linux-gnu/hipe_mkliterals' failed
make[2]: *** [/home/weisslj/src/otp/bin/x86_64-unknown-linux-gnu/hipe_mkliterals] Error 1
make[2]: Leaving directory '/home/weisslj/src/otp/erts/emulator'
/home/weisslj/src/otp/make/run_make.mk:42: recipe for target 'generate' failed
make[1]: *** [generate] Error 2
make[1]: Leaving directory '/home/weisslj/src/otp/erts/emulator'
Makefile:493: recipe for target 'depend' failed
make: *** [depend] Error 2

The minimal set of flags which seems to work for me is LDFLAGS=-no-pie, no added STATIC_CFLAGS, see this table:

STATIC_CFLAGS LDFLAGS Result
HiPE broken
-no-pie OK
-fno-pie HiPE broken
-no-pie -fno-pie OK
-no-pie HiPE broken
-no-pie -no-pie OK
-no-pie -fno-pie HiPE broken
-no-pie -no-pie -fno-pie OK
-fno-pie build error
-fno-pie -no-pie build error
-fno-pie -fno-pie build error
-fno-pie -no-pie -fno-pie build error
-no-pie -fno-pie build error
-no-pie -fno-pie -no-pie OK
-no-pie -fno-pie -fno-pie build error
-no-pie -fno-pie -no-pie -fno-pie OK
-no-pie -Wl,-no-pie HiPE broken
-Wl,-no-pie HiPE broken
-fno-pie -Wl,-no-pie build error

@psyeugenic psyeugenic added team:VM Assigned to OTP team VM fix labels Nov 8, 2016
@sverker
Copy link
Contributor Author

sverker commented Nov 9, 2016

Seems this is the correct and best combination:

STATIC_CFLAGS LDFLAGS
-fno-pie -no-pie

The reason that it failed for you is that CFLAGS was used instead of LDFLAGS at one place (hipe_mkliterals).
I've pushed two more commits. Hopefully it will work better now. I don't have access to
gcc configured with --enable-default-pie so I only tested it with a gcc wrapper script that tries to simulate
--enable-default-pie.

@sverker
Copy link
Contributor Author

sverker commented Nov 9, 2016

If you do get build errors again, please rerun with export V=1 so we can see all arguments passed to gcc.

@weisslj
Copy link
Contributor

weisslj commented Nov 9, 2016

Thanks, now it works perfectly, with gcc and clang. I agree that CFLAGS=-fno-pie and LDFLAGS=-no-pie is the best combination!

@sverker sverker merged commit edfa3b8 into erlang:maint Nov 11, 2016
@sverker
Copy link
Contributor Author

sverker commented Nov 11, 2016

Rebased to two commits and merged to maint and master.

@weisslj
Copy link
Contributor

weisslj commented Nov 11, 2016

Thanks!

@sverker sverker deleted the sverker/hipe-no-pie-amd64 branch June 16, 2022 10:03
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants