Skip to contentSkip to conversation

package/erlang-jiffy: needs -fPIC

PATCH New Fabrice Fontaine 4 participants 8 messages Dec 24, 2020 – Mar 2, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/erlang-jiffy: needs -fPIC

Fixes:
- http://autobuild.buildroot.org/results/9ac6e1bf9eaf922c0b7f869416ec33f40ed3543c

---
 .../0001-rebar.config-add-fPIC.patch          | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 package/erlang-jiffy/0001-rebar.config-add-fPIC.patch
package/erlang-jiffy/0001-rebar.config-add-fPIC.patch new file +43 -0
new file mode 100644
index 0000000000..4809cad03b
@@ -0,0 +1,43 @@
+From 18a2ec2ab855e4762c4adab9a86ec6f601e35de9 Mon Sep 17 00:00:00 2001
+From: Fabrice Fontaine <[email protected]>
+Date: Thu, 24 Dec 2020 10:57:54 +0100
+Subject: [PATCH] rebar.config: add -fPIC
+
+Add -fPIC to avoid the following build failure:
+
+/home/buildroot/autobuild/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/x86_64-buildroot-linux-uclibc/8.3.0/../../../../x86_64-buildroot-linux-uclibc/bin/ld: /tmp/cc0ULrdG.ltrans1.ltrans.o: relocation R_X86_64_PC32 against symbol `dec_destroy' can not be used when making a shared object; recompile with -fPIC
+/home/buildroot/autobuild/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/x86_64-buildroot-linux-uclibc/8.3.0/../../../../x86_64-buildroot-linux-uclibc/bin/ld: final link failed: bad value
+collect2: error: ld returned 1 exit status
+sh(/home/buildroot/autobuild/instance-3/output-1/host/bin/x86_64-linux-g++ c_src/decoder.o c_src/encoder.o c_src/jiffy.o c_src/termstack.o c_src/utf8.o c_src/util.o c_src/doubles.o c_src/objects.o c_src/double-conversion/bignum-dtoa.o c_src/double-conversion/bignum.o c_src/double-conversion/cached-powers.o c_src/double-conversion/diy-fp.o c_src/double-conversion/double-conversion.o c_src/double-conversion/fast-dtoa.o c_src/double-conversion/fixed-dtoa.o c_src/double-conversion/strtod.o  -flto -lstdc++ -flto -lstdc++ -shared  -L/home/buildroot/autobuild/instance-3/output-1/host/x86_64-buildroot-linux-uclibc/sysroot/usr/lib/erlang/lib/erl_interface-3.13.1/lib -lei -o priv/jiffy.so)
+failed with return code 1 and the following output:
+/home/buildroot/autobuild/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/x86_64-buildroot-linux-uclibc/8.3.0/../../../../x86_64-buildroot-linux-uclibc/bin/ld: /tmp/cc0ULrdG.ltrans1.ltrans.o: relocation R_X86_64_PC32 against symbol `dec_destroy' can not be used when making a shared object; recompile with -fPIC
+/home/buildroot/autobuild/instance-3/output-1/host/opt/ext-toolchain/bin/../lib/gcc/x86_64-buildroot-linux-uclibc/8.3.0/../../../../x86_64-buildroot-linux-uclibc/bin/ld: final link failed: bad value
+collect2: error: ld returned 1 exit status
+
+ERROR: Command [compile] failed!
+
+Fixes:
+ - http://autobuild.buildroot.org/results/9ac6e1bf9eaf922c0b7f869416ec33f40ed3543c
+
+Signed-off-by: Fabrice Fontaine <[email protected]>
+[Upstream status: https://github.com/davisp/jiffy/pull/208]
+---
+ rebar.config | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/rebar.config b/rebar.config
+index b951b5e..8bff5e7 100644
+--- a/rebar.config
++++ b/rebar.config
+@@ -15,7 +15,7 @@
+         "CXXFLAGS", "$CXXFLAGS -Ic_src/ -g -Wall $FLTO_FLAG -Werror -O3"},
+ 
+     {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
+-        "LDFLAGS", "$LDFLAGS $FLTO_FLAG -lstdc++"},
++        "LDFLAGS", "$LDFLAGS $FLTO_FLAG -lstdc++ -fPIC"},
+ 
+     %% OS X Leopard flags for 64-bit
+     {"darwin9.*-64$", "CXXFLAGS", "-m64"},
+-- 
+2.29.2
+
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/1 package/erlang-jiffy: needs -fPIC

Hello Fabrice,

Quoted 4 lines · On Thu, 24 Dec 2020 11:14:40 +0100 Fabrice Fontaine…

Fixes:
- http://autobuild.buildroot.org/results/9ac6e1bf9eaf922c0b7f869416ec33f40ed3543c

Thanks for the patch. As usual, I'm kind of interested to understand since when this is happening, why suddenly we need a fix like this. Is this following a version bump of this package ?

Quoted 3 lines

+ {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",

+-        "LDFLAGS", "$LDFLAGS $FLTO_FLAG -lstdc++"},
++        "LDFLAGS", "$LDFLAGS $FLTO_FLAG -lstdc++ -fPIC"},

It is surprising that only LDFLAGS need to be changed. Indeed, -fPIC is also needed at *compile* time when compiling each individual object file, so typically in CFLAGS/CXXFLAGS. Why isn't it needed in CXXFLAGS here ? Because it's already passed at compile time, but forgotten at link time ? Or because LDFLAGS are also used by rebar at compile time ?

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 package/erlang-jiffy: needs -fPIC

Hi Thomas,

Le lun. 28 d?c. 2020 ? 22:53, Thomas Petazzoni
<[email protected]> a ?crit :

Quoted 19 lines

Hello Fabrice,

Quoted 4 lines · On Thu, 24 Dec 2020 11:14:40 +0100 Fabrice Fontaine…

Fixes:
- http://autobuild.buildroot.org/results/9ac6e1bf9eaf922c0b7f869416ec33f40ed3543c

Thanks for the patch. As usual, I'm kind of interested to understand since when this is happening, why suddenly we need a fix like this. Is this following a version bump of this package ?

Quoted 3 lines

+ {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",

+-        "LDFLAGS", "$LDFLAGS $FLTO_FLAG -lstdc++"},
++        "LDFLAGS", "$LDFLAGS $FLTO_FLAG -lstdc++ -fPIC"},
Quoted 5 lines

It is surprising that only LDFLAGS need to be changed. Indeed, -fPIC is also needed at *compile* time when compiling each individual object file, so typically in CFLAGS/CXXFLAGS. Why isn't it needed in CXXFLAGS here ? Because it's already passed at compile time, but forgotten at link time ? Or because LDFLAGS are also used by rebar at compile time ?

This build failure is raised because of the -flto flag which is added since version 1.0.0 and
https://github.com/davisp/jiffy/commit/feaf10f2d50e454f55a9d6b20c289031b0980503
It seems that -flto can't be used without -fPIC.

Quoted 8 lines

Thanks!

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Best Regards,

Fabrice

#3 lore raw

PATCH 1/1 package/erlang-jiffy: needs -fPIC

Quoted 4 lines · On Tue, 29 Dec 2020 10:39:27 +0100 Fabrice Fontaine…

This build failure is raised because of the -flto flag which is added since version 1.0.0 and
https://github.com/davisp/jiffy/commit/feaf10f2d50e454f55a9d6b20c289031b0980503
It seems that -flto can't be used without -fPIC.

This seems super odd. I'm not sure what would be the relationship between LTO and PIC...

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw

PATCH 1/1 package/erlang-jiffy: needs -fPIC

Le mar. 29 d?c. 2020 ? 10:43, Thomas Petazzoni
<[email protected]> a ?crit :

Quoted 11 lines
Quoted 4 lines · On Tue, 29 Dec 2020 10:39:27 +0100 Fabrice Fontaine…

This build failure is raised because of the -flto flag which is added since version 1.0.0 and
https://github.com/davisp/jiffy/commit/feaf10f2d50e454f55a9d6b20c289031b0980503
It seems that -flto can't be used without -fPIC.

This seems super odd. I'm not sure what would be the relationship between LTO and PIC...

Indeed but the build failure is fixed if I remove -flto from CFLAGS. I'll try to understand why ...

Quoted 6 lines

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Best Regards,

Fabrice

#5 lore raw

PATCH 1/1 package/erlang-jiffy: needs -fPIC

Fabrice, Thomas, All,

On 2020-12-29 11:14 +0100, Fabrice Fontaine spake thusly:

Quoted 11 lines

Le mar. 29 d?c. 2020 ? 10:43, Thomas Petazzoni
<[email protected]> a ?crit :

Quoted 9 lines
Quoted 4 lines · On Tue, 29 Dec 2020 10:39:27 +0100 Fabrice Fontaine…

This build failure is raised because of the -flto flag which is added since version 1.0.0 and
https://github.com/davisp/jiffy/commit/feaf10f2d50e454f55a9d6b20c289031b0980503
It seems that -flto can't be used without -fPIC.

Quoted 4 lines
Quoted 2 lines

This seems super odd. I'm not sure what would be the relationship between LTO and PIC...

Indeed but the build failure is fixed if I remove -flto from CFLAGS. I'll try to understand why ...

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.

Regards,
Yann E. MORIN.

Quoted 13 lines
Quoted 6 lines

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Best Regards,

Fabrice
_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#6 lore raw

PATCH 1/1 package/erlang-jiffy: needs -fPIC

Hello,

Quoted 14 lines · On Fri, 1 Jan 2021 11:01:53 +0100 "Yann E. MORIN" <[email protected]>…

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, [...]

Quoted 6 lines

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.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#7 lore raw

PATCH 1/1 package/erlang-jiffy: needs -fPIC

Quoted 23 lines · Thomas Petazzoni

Hello,

Quoted 18 lines · On Fri, 1 Jan 2021 11:01:53 +0100 "Yann E. MORIN" <[email protected]>…

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.

Quoted 5 lines
Quoted 2 lines

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