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

"/usr/bin/ld: warning: creating DT_TEXTREL in a PIE" on x86_32 with OCaml 4.14.1 #12166

Closed
kit-ty-kate opened this issue Apr 5, 2023 · 4 comments
Assignees
Milestone

Comments

@kit-ty-kate
Copy link
Member

I thought #10835 (included in 4.14.0) was supposed to fix this issue (originally reported in #9800), however it seems to still be there in some cases:

#=== ERROR while compiling togglelog.0.1.0 ====================================#
# context              2.2.0~alpha~dev | linux/x86_32 | ocaml-base-compiler.4.14.1 | pinned(https://github.com/WardBrian/togglelog/archive/refs/tags/v0.1.0.tar.gz)
# path                 ~/.opam/4.14/.opam-switch/build/togglelog.0.1.0
# command              ~/.opam/opam-init/hooks/sandbox.sh build dune build -p togglelog -j 127 @install @runtest
# exit-code            1
# env-file             ~/.opam/log/togglelog-8-7b0bed.env
# output-file          ~/.opam/log/togglelog-8-7b0bed.out
### output ###
# (cd _build/default && /home/opam/.opam/4.14/bin/ocamlopt.opt -g -w -24 -o .ppx/0224ad3443a846e54f1637fccb074e7d/ppx.exe /home/opam/.opam/4.14/lib/ocaml/compiler-libs/ocamlcommon.cmxa /home/opam/.opam/4.14/lib/ocaml-compiler-libs/common/ocaml_common.cmxa /home/opam/.opam/4.14/lib/ppxlib/astlib/astlib.cmxa /home/opam/.opam/4.14/lib/stdlib-shims/stdlib_shims.cmxa /home/opam/.opam/4.14/lib/ppxlib/ast/ppxlib_ast.cmxa /home/opam/.opam/4.14/lib/ocaml-compiler-libs/shadow/ocaml_shadow.cmxa /home/opam/.opam/4.14/lib/ppxlib/print_diff/ppxlib_print_diff.cmxa /home/opam/.opam/4.14/lib/ppx_derivers/ppx_derivers.cmxa /home/opam/.opam/4.14/lib/ppxlib/traverse_builtins/ppxlib_traverse_builtins.cmxa /home/opam/.opam/4.14/lib/sexplib0/sexplib0.cmxa /home/opam/.opam/4.14/lib/ppxlib/stdppx/stdppx.cmxa /home/opam/.opam/4.14/lib/ppxlib/ppxlib.cmxa /home/opam/.opam/4.14/lib/ppxlib/metaquot_lifters/ppxlib_metaquot_lifters.cmxa /home/opam/.opam/4.14/lib/ppxlib/metaquot/ppxlib_metaquot.cmxa .ppx/0224ad3443a846e54f1637fccb074e7d/dune__exe___ppx.cmx)
# /usr/bin/ld: /home/opam/.opam/4.14/lib/ppxlib/metaquot/ppxlib_metaquot.a(ppxlib_metaquot.o): warning: relocation in read-only section `.text'
# /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
# (cd _build/default && /home/opam/.opam/4.14/bin/ocamlopt.opt -g -w -24 -o .ppx/8b2b843e2d2a5a5b9cbaea0dd34250ed/ppx.exe /home/opam/.opam/4.14/lib/ocaml/compiler-libs/ocamlcommon.cmxa /home/opam/.opam/4.14/lib/ocaml-compiler-libs/common/ocaml_common.cmxa /home/opam/.opam/4.14/lib/ppxlib/astlib/astlib.cmxa /home/opam/.opam/4.14/lib/stdlib-shims/stdlib_shims.cmxa /home/opam/.opam/4.14/lib/ppxlib/ast/ppxlib_ast.cmxa /home/opam/.opam/4.14/lib/ocaml-compiler-libs/shadow/ocaml_shadow.cmxa /home/opam/.opam/4.14/lib/ppxlib/print_diff/ppxlib_print_diff.cmxa /home/opam/.opam/4.14/lib/ppx_derivers/ppx_derivers.cmxa /home/opam/.opam/4.14/lib/ppxlib/traverse_builtins/ppxlib_traverse_builtins.cmxa /home/opam/.opam/4.14/lib/sexplib0/sexplib0.cmxa /home/opam/.opam/4.14/lib/ppxlib/stdppx/stdppx.cmxa /home/opam/.opam/4.14/lib/ppxlib/ppxlib.cmxa lib/togglelog.cmxa .ppx/8b2b843e2d2a5a5b9cbaea0dd34250ed/dune__exe___ppx.cmx)
# /usr/bin/ld: lib/togglelog.a(togglelog__Mapper.o): warning: relocation in read-only section `.text'
# /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
# (cd _build/default && /home/opam/.opam/4.14/bin/ocamlopt.opt -w -40 -g -o test/log/test.exe test/log/.test.eobjs/native/dune__exe__Test.cmx)
# /usr/bin/ld: test/log/.test.eobjs/native/dune__exe__Test.o: warning: relocation in read-only section `.text'
# /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
# (cd _build/default && /home/opam/.opam/4.14/bin/ocamlopt.opt -w -40 -g -o test/null/test.exe test/null/.test.eobjs/native/dune__exe__Test.cmx)
# /usr/bin/ld: test/null/.test.eobjs/native/dune__exe__Test.o: warning: relocation in read-only section `.text'
# /usr/bin/ld: warning: creating DT_TEXTREL in a PIE

Does anyone know what's happening here?

Detected in ocaml/opam-repository#23615

@lthls
Copy link
Contributor

lthls commented Apr 7, 2023

We won't be supporting 32-bit native code generation anymore, so I don't think there is anything that needs to be done in trunk.
I did look at the relevant issues and PRs though, and I think that what happens is that #10835 only fixes the warnings when creating shared libraries (the shared runtime, .cmxs files), but not executables. I don't understand why (there were comments saying that it should not be added to common_cflags, but nothing about why it wouldn't make sense for mkexe). One possibility is that at that point executables were still not PIE by default, so no warnings were emitted, but now many compilers generate position-independent executables by default. If that's the case, then the solution is likely to either enforce non-PIE executables on 32-bit architectures (like is already done for musl) or patch mkexe in the same way as mksharedlib (now mkdll_flags) was in #10835, adding -Wl,-z,notext.
Either way, I doubt we'll release a 4.14.2 version soon so I'd suggest adding this patch to the opam repository directly if you need this fixed (all versions older than 5.0 will benefit, not only 4.14).

I'm closing this issue for triaging purposes; feel free to keep posting if you want to discuss this further.

@lthls lthls closed this as completed Apr 7, 2023
@xavierleroy
Copy link
Contributor

xavierleroy commented Apr 7, 2023

Like @lthls I'm surprised -no-pie isn't applied when linking an executable on i386, as most Linux distributions have now switched to PIE-by-default mode. I believe -no-pie is preferable (security-wise) to -Wl,-z,notext for building executables, but please correct me if I'm wrong.

We committed on supporting 4.14 in the long term, so a 4.14.2 release is not out of the picture. Allow me keep this issue open while we figure out our plans for 4.14.

@dra27
Copy link
Member

dra27 commented Aug 31, 2023

Side-note for when we get to this for 4.14.2: in 5c71ac0 in #12520 I've fudged CI to avoid the problem for the 32-bit test by holding it to Debian 10 for i386 build; we should revert that commit when this is addressed.

@Octachron
Copy link
Member

This issue has been fixed by #12993 which marks 32 executable as noPIE by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants