[Buildroot] [PATCH 1/1] package/erlang-jiffy: needs -fPIC

Arnout Vandecappelle arnout at mind.be
Tue Mar 2 22:49:06 UTC 2021



On 01/01/2021 11:37, Thomas Petazzoni wrote:
> Hello,
> 
> On Fri, 1 Jan 2021 11:01:53 +0100
> "Yann E. MORIN" <yann.morin.1998 at free.fr> wrote:
> 
>> The thing with LTO, is that all files should (but in practice: must) be
>> compiled with the same set of options; from the gcc man page:
>>
>>     It is recommended that you compile all the files participating in
>>     the same link with the same options and also specify those options
>>     at link time.
>>
>> and later:
>>
>>     There are some code generation flags preserved by GCC when generating
>>     bytecodes, as they need to be used during the final link. Currently,
>>     the following options and their settings are taken from the first
>>     object file that explicitly specifies them: -fPIC, [...]
>>
>> So, if one file is compiled with -fPIC, then this is recorded in the .o
>> for that file, which gcc notices later when doing the link, and thus all
>> files must be -fPIC.
>>
>> This can be a file compiled by the package itself, or it may come from
>> an external (staging) static library.
> 
> Ah, this is indeed an interesting explanation, which could explain why
> adding it just to LDFLAGS solves the problem.

 I dove a bit into this.

 erlang-jiffy indeed enables LTO if the compiler supports it.

 It passes -fPIC during build, but not during link. This particular build
failure was with BR2_PIC_PIE=y - for some reason, when BR2_PIC_PIE is not set,
-FPIC *is* called during link already... And in fact, the addition of -fPIC
during link has the effect of cancelling the -fPIE that the toolchain wrapper
would otherwise add. Without BR2_PIC_PIE=y, the build succeeds even though no
-fPIC is passed during link. So the problem really is that BR2_PIC_PIE adds
-fPIE during link but not during build.

 However, the real question is: why does rebar add -fPIC during build but not
during link? I think this is something that should be fixed at the level of
rebar itself, not in individual packages.


 Regards,
 Arnout



More information about the buildroot mailing list