Skip to contentSkip to conversation

package/pkg-meson: handle b_pie

PATCH New Fabrice Fontaine 3 participants 6 messages May 28, 2021 – Jun 1, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/pkg-meson: handle b_pie

pipewire unconditionally enables b_pie since version 0.3.20 and
https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/abe73c9146cd223b40b22581b1fd58bc044c671e
which will raise the following build failure on m68k since commit a6d88d3ba5e30e11f4d726f341bc56c1be7c71c9:

/srv/storage/autobuild/run/instance-1/output-1/host/opt/ext-toolchain/bin/../lib/gcc/m68k-buildroot-linux-uclibc/9.3.0/../../../../m68k-buildroot-linux-uclibc/bin/ld: /srv/storage/autobuild/run/instance-1/output-1/host/m68k-buildroot-linux-uclibc/sysroot/usr/lib/Scrt1.o: in function `lib_main':
(.text+0x4): undefined reference to `__shared_flat_add_library'

Fixes:
- http://autobuild.buildroot.org/results/c258a2736661af8ea73abeda2503d8682e65f1e2

---
 package/pkg-meson.mk | 1 +
 1 file changed, 1 insertion(+)
package/pkg-meson.mk +1 -0
index a57820d4d2..a55063d58e 100644
@@ -91,6 +91,7 @@ define $(2)_CONFIGURE_CMDS
 		--default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
 		--buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release) \
 		--cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
+		-Db_pie=$(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),true,false) \
 		-Dstrip=false \
 		-Dbuild.pkg_config_path=$$(HOST_DIR)/lib/pkgconfig \
 		$$($$(PKG)_CONF_OPTS) \
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/1 package/pkg-meson: handle b_pie

Fabrice, All,

+Peter, +James

On 2021-05-28 21:17 +0200, Fabrice Fontaine spake thusly:

Quoted 21 lines

pipewire unconditionally enables b_pie since version 0.3.20 and
https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/abe73c9146cd223b40b22581b1fd58bc044c671e
which will raise the following build failure on m68k since commit a6d88d3ba5e30e11f4d726f341bc56c1be7c71c9:

/srv/storage/autobuild/run/instance-1/output-1/host/opt/ext-toolchain/bin/../lib/gcc/m68k-buildroot-linux-uclibc/9.3.0/../../../../m68k-buildroot-linux-uclibc/bin/ld: /srv/storage/autobuild/run/instance-1/output-1/host/m68k-buildroot-linux-uclibc/sysroot/usr/lib/Scrt1.o: in function `lib_main':
(.text+0x4): undefined reference to `__shared_flat_add_library'

Fixes:
- http://autobuild.buildroot.org/results/c258a2736661af8ea73abeda2503d8682e65f1e2

---
 package/pkg-meson.mk | 1 +
 1 file changed, 1 insertion(+)
package/pkg-meson.mk +0 -0
index a57820d4d2..a55063d58e 100644

package/pkg-meson.mk define $(2)_CONFIGURE_CMDS · line 94

Quoted 4 lines
package/pkg-meson.mk +1 -0
@@ -91,6 +91,7 @@ define $(2)_CONFIGURE_CMDS
 		--default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
 		--buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release) \
 		--cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
+		-Db_pie=$(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),true,false) \

I was wondering if we should not also put that in the cross-compilation file as well, or even only in the cross-compilation file.

I see, below, that strip is on the command line, and not in the cross-compilation file. However, the meson documentation [0] states that the precendence of options is:

- command line
- machine file
- build-system definition

So, b providing the default in the cross-compilation file, we also ensure it is available in the file (and the template) we install in $(HOST_DIR)/etc/meson/cross-compilation.conf and in $(HOST_DIR)/etc/meson/cross-compilation.conf.in, so that builds outside of Buildroot (e.g. SDK) by default use the same values as the builds in Buildroot, but that users can still override that on the command line.

Thoughts?

In the meantime, I think it is still correct to have b_pie on the command line for our infra, like we have strip, so: applied to master, thanks.

[0] https://mesonbuild.com/Machine-files.html#meson-builtin-options

package/pkg-meson.mk define $(2)_CONFIGURE_CMDS · line 95

Quoted 1 line
package/pkg-meson.mk +0 -0
 		-Dstrip=false \

And strip should probably also go in the cross-compilation file, too, nmaybe?

Or is there a rule that says "this type of option should go in the cross file, anything else should go on the cokmmand line" ?

Regards,
Yann E. MORIN.

Quoted 9 lines
package/pkg-meson.mk +0 -0
 		-Dbuild.pkg_config_path=$$(HOST_DIR)/lib/pkgconfig \
 		$$($$(PKG)_CONF_OPTS) \
Signature · 6 lines
2.30.2

_______________________________________________
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.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

PATCH 1/1 package/pkg-meson: handle b_pie

Fabrice, All,

On 2021-05-29 11:09 +0200, Yann E. MORIN spake thusly:

Quoted 17 lines

On 2021-05-28 21:17 +0200, Fabrice Fontaine spake thusly:

Quoted 16 lines

pipewire unconditionally enables b_pie since version 0.3.20 and
https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/abe73c9146cd223b40b22581b1fd58bc044c671e
which will raise the following build failure on m68k since commit a6d88d3ba5e30e11f4d726f341bc56c1be7c71c9:

/srv/storage/autobuild/run/instance-1/output-1/host/opt/ext-toolchain/bin/../lib/gcc/m68k-buildroot-linux-uclibc/9.3.0/../../../../m68k-buildroot-linux-uclibc/bin/ld: /srv/storage/autobuild/run/instance-1/output-1/host/m68k-buildroot-linux-uclibc/sysroot/usr/lib/Scrt1.o: in function `lib_main':
(.text+0x4): undefined reference to `__shared_flat_add_library'

Fixes:
- http://autobuild.buildroot.org/results/c258a2736661af8ea73abeda2503d8682e65f1e2

---
 package/pkg-meson.mk | 1 +
 1 file changed, 1 insertion(+)
Quoted 9 lines

package/pkg-meson.mk define $(2)_CONFIGURE_CMDS · line 94

Quoted 9 lines
package/pkg-meson.mk +1 -0
index a57820d4d2..a55063d58e 100644
@@ -91,6 +91,7 @@ define $(2)_CONFIGURE_CMDS
 		--default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
 		--buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release) \
 		--cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
+		-Db_pie=$(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),true,false) \

[--SNIP--]

Quoted 3 lines

In the meantime, I think it is still correct to have b_pie on the command line for our infra, like we have strip, so: applied to master, thanks.

Given a later patch that arrived in parallel, it turns out this patch was not correct, and that we still have a bit of interrogation on that, so I've reverted it, sorry. I'll keep an eye on the discussions...

Regards,
Yann E. MORIN.

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.  |
'------------------------------^-------^------------------^--------------------'
#3 lore raw

PATCH 1/1 package/pkg-meson: handle b_pie

Dear all,

Le sam. 29 mai 2021 ? 11:21, Yann E. MORIN <[email protected]> a ?crit :

Quoted 31 lines

Fabrice, All,

On 2021-05-29 11:09 +0200, Yann E. MORIN spake thusly:

Quoted 17 lines

On 2021-05-28 21:17 +0200, Fabrice Fontaine spake thusly:

Quoted 16 lines

pipewire unconditionally enables b_pie since version 0.3.20 and
https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/abe73c9146cd223b40b22581b1fd58bc044c671e
which will raise the following build failure on m68k since commit a6d88d3ba5e30e11f4d726f341bc56c1be7c71c9:

/srv/storage/autobuild/run/instance-1/output-1/host/opt/ext-toolchain/bin/../lib/gcc/m68k-buildroot-linux-uclibc/9.3.0/../../../../m68k-buildroot-linux-uclibc/bin/ld: /srv/storage/autobuild/run/instance-1/output-1/host/m68k-buildroot-linux-uclibc/sysroot/usr/lib/Scrt1.o: in function `lib_main':
(.text+0x4): undefined reference to `__shared_flat_add_library'

Fixes:
- http://autobuild.buildroot.org/results/c258a2736661af8ea73abeda2503d8682e65f1e2

---
 package/pkg-meson.mk | 1 +
 1 file changed, 1 insertion(+)
Quoted 9 lines

package/pkg-meson.mk define $(2)_CONFIGURE_CMDS · line 94

Quoted 9 lines
package/pkg-meson.mk +1 -0
index a57820d4d2..a55063d58e 100644
@@ -91,6 +91,7 @@ define $(2)_CONFIGURE_CMDS
            --default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
            --buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release) \
            --cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
+           -Db_pie=$(if $(BR2_TOOLCHAIN_SUPPORTS_PIE),true,false) \

[--SNIP--]

Quoted 7 lines
Quoted 3 lines

In the meantime, I think it is still correct to have b_pie on the command line for our infra, like we have strip, so: applied to master, thanks.

Given a later patch that arrived in parallel, it turns out this patch was not correct, and that we still have a bit of interrogation on that, so I've reverted it, sorry. I'll keep an eye on the discussions...

I think that the second version of this patch (i.e. always disabling b_pie through command line) is the best option because:
- PIE is already enabled by the toolchain-wrapper:
hardening-check output/build/pipewire-0.3.26/build/spa/plugins/audioconvert/benchmark-resample output/build/pipewire-0.3.26/build/spa/plugins/audioconvert/benchmark-resample:
Position Independent Executable: yes
- Enabling PIE in two different places is not future-proof and is not done in any other infrastructures (autotools, cmake, etc.). I think this is also the reason why strip is unconditionally disabled in the command line (it is already handled in Makefile.in)

Quoted 11 lines

Regards,
Yann E. MORIN.

--
.-----------------.--------------------.------------------.--------------------.

|  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.  |

'------------------------------^-------^------------------^--------------------'

Best Regards,

Fabrice

#4 lore raw

PATCH 1/1 package/pkg-meson: handle b_pie

Fabrice, All,

Meson experts, questions for you below!

On 2021-05-29 11:41 +0200, Fabrice Fontaine spake thusly:

Quoted 4 lines

Le sam. 29 mai 2021 ? 11:21, Yann E. MORIN <[email protected]> a ?crit :

Quoted 2 lines

On 2021-05-29 11:09 +0200, Yann E. MORIN spake thusly:

Quoted 1 line

On 2021-05-28 21:17 +0200, Fabrice Fontaine spake thusly:

[--SNIP--]

Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
package/pkg-meson.mk +0 -0
index a57820d4d2..a55063d58e 100644
@@ -91,6 +91,7 @@ define $(2)_CONFIGURE_CMDS
            --default-library=$(if
            $(BR2_STATIC_LIBS),static,shared) \
            --buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release)
            \
            --cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
package/pkg-meson.mk +1 -0
            \
+           -Db_pie=$(if

$(BR2_TOOLCHAIN_SUPPORTS_PIE),true,false) \

Given a later patch that arrived in parallel, it turns out this patch
was not correct, and that we still have a bit of interrogation on that,
so I've reverted it, sorry. I'll keep an eye on the discussions...

Quoted 7 lines

I think that the second version of this patch (i.e. always disabling b_pie through command line) is the best option because:
- PIE is already enabled by the toolchain-wrapper:
hardening-check output/build/pipewire-0.3.26/build/spa/plugins/audioconvert/benchmark-resample output/build/pipewire-0.3.26/build/spa/plugins/audioconvert/benchmark-resample:
Position Independent Executable: yes

OK, so PIE is indeed applied when building, good.

Quoted 2 lines

- Enabling PIE in two different places is not future-proof and is not done in any other infrastructures (autotools, cmake, etc.).

Yeah, that makes perfect sense.

Quoted 3 lines

I think
this is also the reason why strip is unconditionally disabled in the command line (it is already handled in Makefile.in)

Yeah, I know about strip. However, my question for the meson experts in the room, is: should we leave that (strip, b_pie) on the command line, or should we have them in the cross-compilation file?

Additionaly, the machine-files documentation [0] lists pkg_config_path as being part of the builtin options, so shouldn't we also push that into the cross-compilation file?

As of today, we have two places where we push meson options: the command line, and the cross-compilation file. To further Fanrice's argument:
having two places where we push options is not very consistent and future-proof.

Basically, that would give a patch like (@HOST_DIR@ is already replaced):

    diff --git a/package/meson/cross-compilation.conf.in b/package/meson/cross-compilation.conf.in
    index 37b49eea3b..942f68f008 100644
    --- a/package/meson/cross-compilation.conf.in
    +++ b/package/meson/cross-compilation.conf.in
    @@ -13,6 +13,9 @@ g-ir-compiler = '@STAGING_DIR@/usr/bin/g-ir-compiler'
     g-ir-scanner = '@STAGING_DIR@/usr/bin/g-ir-scanner'
     
     [built-in options]
    +b_pie = false
    +strip = false
    +build.pkg_config_path = '@HOST_DIR@/lib/pkgconfig'
     c_args = [@TARGET_CFLAGS@]
     c_link_args = [@TARGET_LDFLAGS@]
     cpp_args = [@TARGET_CXXFLAGS@]
    diff --git a/package/pkg-meson.mk b/package/pkg-meson.mk
    index 1857450564..87cf0e3dd7 100644
    --- a/package/pkg-meson.mk
    +++ b/package/pkg-meson.mk
    @@ -91,9 +91,6 @@ define $(2)_CONFIGURE_CMDS
     		--default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
     		--buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release) \
     		--cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
    -		-Db_pie=false \
    -		-Dstrip=false \
    -		-Dbuild.pkg_config_path=$$(HOST_DIR)/lib/pkgconfig \
     		$$($$(PKG)_CONF_OPTS) \
     		$$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
     endef

As far as I can tell from the documentation, this really seems like this should be what we want to do in Buildroot, because that way, these settings will also be used for the SDK, or for building manually outside of Buildroot...

So, what's your thoughts about that?

Regards,
Yann E. MORIN.

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.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

PATCH 1/1 package/pkg-meson: handle b_pie

Quoted 43 lines · Yann E. MORIN

Fabrice, All,

Meson experts, questions for you below!

On 2021-05-29 11:41 +0200, Fabrice Fontaine spake thusly:

Quoted 4 lines

Le sam. 29 mai 2021 ? 11:21, Yann E. MORIN <[email protected]> a ?crit :

Quoted 2 lines

On 2021-05-29 11:09 +0200, Yann E. MORIN spake thusly:

Quoted 1 line

On 2021-05-28 21:17 +0200, Fabrice Fontaine spake thusly:

[--SNIP--]

Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
package/pkg-meson.mk +0 -0
index a57820d4d2..a55063d58e 100644
@@ -91,6 +91,7 @@ define $(2)_CONFIGURE_CMDS
            --default-library=$(if
            $(BR2_STATIC_LIBS),static,shared) \
            --buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release)
            \
            --cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
package/pkg-meson.mk +1 -0
            \
+           -Db_pie=$(if

$(BR2_TOOLCHAIN_SUPPORTS_PIE),true,false) \

Given a later patch that arrived in parallel, it turns out this patch
was not correct, and that we still have a bit of interrogation on that,
so I've reverted it, sorry. I'll keep an eye on the discussions...

Quoted 7 lines

I think that the second version of this patch (i.e. always disabling b_pie through command line) is the best option because:
- PIE is already enabled by the toolchain-wrapper:
hardening-check output/build/pipewire-0.3.26/build/spa/plugins/audioconvert/benchmark-resample output/build/pipewire-0.3.26/build/spa/plugins/audioconvert/benchmark-resample:
Position Independent Executable: yes

OK, so PIE is indeed applied when building, good.

Quoted 2 lines

- Enabling PIE in two different places is not future-proof and is not done in any other infrastructures (autotools, cmake, etc.).

Yeah, that makes perfect sense.

Quoted 7 lines
Quoted 3 lines

I think
this is also the reason why strip is unconditionally disabled in the command line (it is already handled in Makefile.in)

Yeah, I know about strip. However, my question for the meson experts in the room, is: should we leave that (strip, b_pie) on the command line, or should we have them in the cross-compilation file?

Well, currently we pass them in the toolchain wrapper.

If we would put -fPIE in the cflags in the cross-compilation file, we'd hit
this message:

if '-f' + arg.lower() in all_flags or '-f' + arg.upper() in all_flags:
mlog.warning("Use the '{}' kwarg instead of passing '{}' manually to
{!r}".format(arg, '-f' + arg, self.name))
return True

But now, meson doesn't notice because we hide it in the wrapper.

Anyway, the only effect of b_pie (or various other ways of passing the same
option) is that it adds -fPIE to the compilation flags. So I don't think it's useful to set b_pie.

Quoted 3 lines

Additionaly, the machine-files documentation [0] lists pkg_config_path as being part of the builtin options, so shouldn't we also push that into the cross-compilation file?

Yes, that's just accidental. It was passed as a command-line option in the
weston package, and later refactored in the core package-meson in commit 5cff3a8bdfba92e9f61d0984df08f1ecd205c072 - but still keeping it as a command-line option.

Quoted 27 lines

As of today, we have two places where we push meson options: the command line, and the cross-compilation file. To further Fanrice's argument:
having two places where we push options is not very consistent and future-proof.

Basically, that would give a patch like (@HOST_DIR@ is already replaced):

    diff --git a/package/meson/cross-compilation.conf.in b/package/meson/cross-compilation.conf.in
    index 37b49eea3b..942f68f008 100644
    --- a/package/meson/cross-compilation.conf.in
    +++ b/package/meson/cross-compilation.conf.in
    @@ -13,6 +13,9 @@ g-ir-compiler = '@STAGING_DIR@/usr/bin/g-ir-compiler'
     g-ir-scanner = '@STAGING_DIR@/usr/bin/g-ir-scanner'
     
     [built-in options]
    +b_pie = false
    +strip = false
    +build.pkg_config_path = '@HOST_DIR@/lib/pkgconfig'
     c_args = [@TARGET_CFLAGS@]
     c_link_args = [@TARGET_LDFLAGS@]
     cpp_args = [@TARGET_CXXFLAGS@]
    diff --git a/package/pkg-meson.mk b/package/pkg-meson.mk
    index 1857450564..87cf0e3dd7 100644
    --- a/package/pkg-meson.mk
    +++ b/package/pkg-meson.mk
    @@ -91,9 +91,6 @@ define $(2)_CONFIGURE_CMDS
     		--default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
Quoted 8 lines
     		--buildtype=$(if $(BR2_ENABLE_DEBUG),debug,release) \
     		--cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
    -		-Db_pie=false \
    -		-Dstrip=false \
    -		-Dbuild.pkg_config_path=$$(HOST_DIR)/lib/pkgconfig \
     		$$($$(PKG)_CONF_OPTS) \
     		$$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
     endef

LGTM.

Regards,
Arnout

Quoted 10 lines

As far as I can tell from the documentation, this really seems like this should be what we want to do in Buildroot, because that way, these settings will also be used for the SDK, or for building manually outside of Buildroot...

So, what's your thoughts about that?

Regards,
Yann E. MORIN.