Re: [PATCH v2 02/18] make: add -fPIE flag
- From
Collin Funk <collin.funk1@gmail.com>
- Date
- Sep 19, 2025, 23:59 UTC
- Message-ID
- <87plbmyox4.fsf@gmail.com>
- In-Reply-To
- <xmqqa52qypo8.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 27 quoted lines
> Ezekiel Newren <ezekielnewren@gmail.com> writes: > >> On Fri, Sep 19, 2025 at 2:07 PM Junio C Hamano <gitster@pobox.com> wrote: >>> >>> Ezekiel Newren <ezekielnewren@gmail.com> writes: >>> >>> > I was trying to get the rust compiler to link against libgit.a. Both >>> > Meson and Makefile produce libgit.a. No changes were to meson.build >>> > were necessary for that to work, but but with Makefile I would get >>> > errors like: >>> > relocation R_X86_64_32 against `.rodata' can not be used when making a >>> > PIE object; recompile with -fPIE >>> >>> This sounds like a workaround that is somewhat platform and compiler >>> specific limitation, at least to me. Does this need to be conditional >>> and if so on what? >> >> I don't know, but I have another question to add to yours. Why does >> Make need -fPIE in order for the Rust compiler to link against >> libgit.a created by Make, when Meson doesn't seem to specify PIE >> anywhere and yet the Rust compiler can work with Meson's libgit.a >> output? > > I do not know what the build procedure using meson exactly does to > create a library archive. On the Make side, we do not compile for > position independence, and don't do anything other than bog standard > "ar rcs". Patrick, any hint?
Not too familiar with Rust, but looks like the answer is here [1]. Specificially, this part:
pic - fully relocatable position independent code, machine
instructions need to use relative addressing modes. Equivalent to
the "uppercase" -fPIC or -fPIE options in other compilers, depending
on the produced crate types. This is the default model for majority
of supported targets.Collin
[1] https://doc.rust-lang.org/rustc/codegen-options/index.html#relocation-model