Skip to contentSkip to conversation

poky-tiny: enable section removal

PATCH Superseded Sinan Kaya 3 participants 5 messages Nov 9, 2020 – Nov 10, 2020

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

PATCH v3 1/1 poky-tiny: enable section removal

Use GCC sections flags so that unused sections can be garbage collected at link time.

---
 meta-poky/conf/distro/poky-tiny.conf | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
meta-poky/conf/distro/poky-tiny.conf +18 -0
index c6d4b88f83d..1e37394875d 100644
@@ -122,3 +122,21 @@ PNBLACKLIST[core-image-weston] = "not buildable with poky-tiny"
 
 # Disable python usage in opkg-utils since it won't build with tiny config
 PACKAGECONFIG_remove_pn-opkg-utils = "python"
+
+# set default for all targets
+CFLAGS_append = " -ffunction-sections -fdata-sections"
+LDFLAGS_append = " -Wl,--gc-sections"
+
+# gc-sections requires either an entry or an undefined symbol
+CFLAGS_remove_pn-glibc = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-glibc = "-Wl,--gc-sections"
+
+# perl won't cross compile with sections
+CFLAGS_remove_pn-perl = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-perl = "-Wl,--gc-sections"
+
+# Unknown float word ordering. You need to manually preset
+CFLAGS_remove_pn-cairo = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-cairo = "-Wl,--gc-sections"
+
+
Signature · 1 line
2.17.1
#1 lore raw
Quoted 25 lines · Sinan Kaya

Use GCC sections flags so that unused sections can be garbage collected at link time.

---
 meta-poky/conf/distro/poky-tiny.conf | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
meta-poky/conf/distro/poky-tiny.conf +8 -0
index c6d4b88f83d..1e37394875d 100644
@@ -122,3 +122,21 @@ PNBLACKLIST[core-image-weston] = "not buildable with poky-tiny"
 
 # Disable python usage in opkg-utils since it won't build with tiny config
 PACKAGECONFIG_remove_pn-opkg-utils = "python"
+
+# set default for all targets
+CFLAGS_append = " -ffunction-sections -fdata-sections"
+LDFLAGS_append = " -Wl,--gc-sections"
+
+# gc-sections requires either an entry or an undefined symbol
+CFLAGS_remove_pn-glibc = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-glibc = "-Wl,--gc-sections"

meta-poky/conf/distro/poky-tiny.conf PNBLACKLIST[core-image-weston] = "not buildable with poky-tiny" · line 142

Quoted 10 lines
meta-poky/conf/distro/poky-tiny.conf +10 -0
+
+# perl won't cross compile with sections
+CFLAGS_remove_pn-perl = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-perl = "-Wl,--gc-sections"
+
+# Unknown float word ordering. You need to manually preset
+CFLAGS_remove_pn-cairo = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-cairo = "-Wl,--gc-sections"
+
+

Using _remove in a common layer like this is discouraged as it's very difficult to override anywhere else.

I'd recommend defining new variables with default values which enable the flags you want then append them to CFLAGS and LDFLAGS respectively. This allows the new variables to be overridden per package very easily. Also consider that you may want to apply these only for the target and not for native/nativesdk packages.

Here's a quick untested example:

CFLAGS_SECTION_REMOVAL = "-ffunction-sections -fdata-sections" LDFLAGS_SECTION_REMOVAL = "-Wl,--gc-sections"

CFLAGS_SECTION_REMOVAL_pn-glibc = ""
LDFLAGS_SECTION_REMOVAL_pn-glibc = ""
CFLAGS_SECTION_REMOVAL_pn-perl = ""
LDFLAGS_SECTION_REMOVAL_pn-perl = ""
CFLAGS_SECTION_REMOVAL_pn-cairo = ""
LDFLAGS_SECTION_REMOVAL_pn-cairo = ""

CFLAGS_append_class-target = " ${CFLAGS_SECTION_REMOVAL}" LDFLAGS_append_class-target = " ${LDFLAGS_SECTION_REMOVAL}"

You could also look at meta/conf/distro/include/security_flags.inc in oe-core as an example.

And lastly it looks like you have a couple of extra newlines added at the end of the file, these can be dropped.

Thanks,

Signature · 2 lines
Paul Barker
Konsulko Group
author
#2 lore raw
Quoted 56 lines · Paul Barker
Quoted 24 lines · Sinan Kaya

Use GCC sections flags so that unused sections can be garbage collected at link time.

---
 meta-poky/conf/distro/poky-tiny.conf | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
meta-poky/conf/distro/poky-tiny.conf +8 -0
index c6d4b88f83d..1e37394875d 100644
@@ -122,3 +122,21 @@ PNBLACKLIST[core-image-weston] = "not buildable with poky-tiny"
 
 # Disable python usage in opkg-utils since it won't build with tiny config
 PACKAGECONFIG_remove_pn-opkg-utils = "python"
+
+# set default for all targets
+CFLAGS_append = " -ffunction-sections -fdata-sections"
+LDFLAGS_append = " -Wl,--gc-sections"
+
+# gc-sections requires either an entry or an undefined symbol
+CFLAGS_remove_pn-glibc = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-glibc = "-Wl,--gc-sections"

meta-poky/conf/distro/poky-tiny.conf PNBLACKLIST[core-image-weston] = "not buildable with poky-tiny" · line 142

Quoted 10 lines
meta-poky/conf/distro/poky-tiny.conf +10 -0
+
+# perl won't cross compile with sections
+CFLAGS_remove_pn-perl = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-perl = "-Wl,--gc-sections"
+
+# Unknown float word ordering. You need to manually preset
+CFLAGS_remove_pn-cairo = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-cairo = "-Wl,--gc-sections"
+
+

Using _remove in a common layer like this is discouraged as it's very difficult to override anywhere else.

I'd recommend defining new variables with default values which enable the flags you want then append them to CFLAGS and LDFLAGS respectively. This allows the new variables to be overridden per package very easily. Also consider that you may want to apply these only for the target and not for native/nativesdk packages.

Here's a quick untested example:

CFLAGS_SECTION_REMOVAL = "-ffunction-sections -fdata-sections" LDFLAGS_SECTION_REMOVAL = "-Wl,--gc-sections"

CFLAGS_SECTION_REMOVAL_pn-glibc = ""
LDFLAGS_SECTION_REMOVAL_pn-glibc = ""
CFLAGS_SECTION_REMOVAL_pn-perl = ""
LDFLAGS_SECTION_REMOVAL_pn-perl = ""
CFLAGS_SECTION_REMOVAL_pn-cairo = ""
LDFLAGS_SECTION_REMOVAL_pn-cairo = ""

Quoted 5 lines

CFLAGS_append_class-target = " ${CFLAGS_SECTION_REMOVAL}" LDFLAGS_append_class-target = " ${LDFLAGS_SECTION_REMOVAL}"

You could also look at meta/conf/distro/include/security_flags.inc in oe-core as an example.

Makes sense.

Quoted 3 lines

And lastly it looks like you have a couple of extra newlines added at the end of the file, these can be dropped.

Sure, let me look. It must be left over there when I removed other configs.

Quoted 5 lines

Thanks,

-- Paul Barker Konsulko Group

#3 lore raw
In reply to Sinan Kaya
Quoted 26 lines · Sinan Kaya

Use GCC sections flags so that unused sections can be garbage collected at link time.

---
 meta-poky/conf/distro/poky-tiny.conf | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
meta- renamed from meta-poky/conf/distro/poky-tiny.conf +0 -0

poky/conf/distro/poky-tiny.conf
index c6d4b88f83d..1e37394875d 100644

meta-poky/conf/distro/poky-tiny.conf +0 -0
@@ -122,3 +122,21 @@ PNBLACKLIST[core-image-weston] = "not buildable

with poky-tiny"

# Disable python usage in opkg-utils since it won't build with tiny
config
PACKAGECONFIG_remove_pn-opkg-utils = "python"

meta-poky/conf/distro/poky-tiny.conf +7 -0
+
+# set default for all targets
+CFLAGS_append = " -ffunction-sections -fdata-sections"
+LDFLAGS_append = " -Wl,--gc-sections"
+
+# gc-sections requires either an entry or an undefined symbol
+CFLAGS_remove_pn-glibc = "-ffunction-sections -fdata-sections"

meta-poky/conf/distro/poky-tiny.conf PNBLACKLIST[core-image-weston] = "not buildable with poky-tiny" · line 141

Quoted 10 lines
meta-poky/conf/distro/poky-tiny.conf +10 -0
+LDFLAGS_remove_pn-glibc = "-Wl,--gc-sections"
+
+# perl won't cross compile with sections
+CFLAGS_remove_pn-perl = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-perl = "-Wl,--gc-sections"
+
+# Unknown float word ordering. You need to manually preset
+CFLAGS_remove_pn-cairo = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-cairo = "-Wl,--gc-sections"
+

Whilst earlier versions passed testing, this one didn't:

https://autobuilder.yoctoproject.org/typhoon/#/builders/15/builds/2949

Cheers,

Richard

author
#4 lore raw
Quoted 4 lines · Richard Purdie
Quoted 4 lines
meta-poky/conf/distro/poky-tiny.conf +4 -0
+# perl won't cross compile with sections
+CFLAGS_remove_pn-perl = "-ffunction-sections -fdata-sections"
+LDFLAGS_remove_pn-perl = "-Wl,--gc-sections"
+

[snip]

Quoted 4 lines
Quoted 1 line

+

Whilst earlier versions passed testing, this one didn't:

https://autobuilder.yoctoproject.org/typhoon/#/builders/15/builds/2949

Thanks, I saw build error on dunfell. Maybe, the issue is fixed upstream. I'll omit perl change on next revision.