Skip to contentSkip to conversation

m68k: Enable dead code elimination

PATCH In review Daniel Palmer 4 participants 11 messages Apr 16, 2025 – Jul 6, 2025 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 m68k: Enable dead code elimination

Allow the experimental dead code elimination config to be enabled.

For my 68000 nommu config this frees up a few hundred K of memory so seems worth while.

Boot and build tested on nommu and mmu enabled configs.

Before:
Memory: 5388K/8192K available (1986K kernel code, 114K rwdata, 244K rodata, 92K init, 41K bss, 2624K reserved, 0K cma-reserved)

After
Memory: 5684K/8192K available (1714K kernel code, 112K rwdata, 228K rodata, 92K init, 37K bss, 2328K reserved, 0K cma-reserved)

---
 arch/m68k/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/m68k/Kconfig +1 -0
index eb5bb6d36899..11835eb59d94 100644
@@ -32,6 +32,7 @@ config M68K
 	select HAVE_ASM_MODVERSIONS
 	select HAVE_DEBUG_BUGVERBOSE
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS if !CPU_HAS_NO_UNALIGNED
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_UID16
 	select MMU_GATHER_NO_RANGE if MMU
Signature · 1 line
2.47.2
Acked-by on v1 1/1
#1 lore raw

Hi Daniel,

Quoted 11 lines · Daniel Palmer

Allow the experimental dead code elimination config to be enabled.

For my 68000 nommu config this frees up a few hundred K of memory so seems worth while.

Boot and build tested on nommu and mmu enabled configs.

Before:
Memory: 5388K/8192K available (1986K kernel code, 114K rwdata, 244K rodata, 92K init, 41K bss, 2624K reserved, 0K cma-reserved)

Quoted 5 lines

After
Memory: 5684K/8192K available (1714K kernel code, 112K rwdata, 228K rodata, 92K init, 37K bss, 2328K reserved, 0K cma-reserved)

Nice. It worked fine on ColdFire builds as well (both nommu and mmu).

I notice that some other architectures (arm and powerpc) have version checks on gcc or ld in the config. Do you know if there is any version limitations for m68k here?

Regards
Greg

Quoted 16 lines
---
  arch/m68k/Kconfig | 1 +
  1 file changed, 1 insertion(+)
arch/m68k/Kconfig +1 -0
index eb5bb6d36899..11835eb59d94 100644
@@ -32,6 +32,7 @@ config M68K
  	select HAVE_ASM_MODVERSIONS
  	select HAVE_DEBUG_BUGVERBOSE
  	select HAVE_EFFICIENT_UNALIGNED_ACCESS if !CPU_HAS_NO_UNALIGNED
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
  	select HAVE_MOD_ARCH_SPECIFIC
  	select HAVE_UID16
  	select MMU_GATHER_NO_RANGE if MMU
#2 lore raw

Hi Greg,

Quoted 3 lines · Greg Ungerer

I notice that some other architectures (arm and powerpc) have version checks on gcc or ld in the config. Do you know if there is any version limitations for m68k here?

I'm not sure about that. I'll try to work out why they have the checks and see if that affects m68k too.
I'm using GCC13 so probably new enough that most things work.

Cheers,

Daniel

#3 lore raw

Hi Daniel,

Quoted 10 lines · Daniel Palmer

Hi Greg,

Quoted 3 lines · Greg Ungerer

I notice that some other architectures (arm and powerpc) have version checks on gcc or ld in the config. Do you know if there is any version limitations for m68k here?

I'm not sure about that. I'll try to work out why they have the checks and see if that affects m68k too.
I'm using GCC13 so probably new enough that most things work.

FWIW, the oldest toolchain I had lying around was based on gcc 8.3.0 and binutils 2.32. This patch worked fine on that.

Regards
Greg

#4 lore raw
Quoted 7 lines · Greg Ungerer
Quoted 6 lines · Daniel Palmer
Quoted 3 lines · Greg Ungerer

I notice that some other architectures (arm and powerpc) have version checks on gcc or ld in the config. Do you know if there is any version limitations for m68k here?

Quoted 7 lines
Quoted 3 lines

I'm not sure about that. I'll try to work out why they have the checks and see if that affects m68k too. I'm using GCC13 so probably new enough that most things work.

FWIW, the oldest toolchain I had lying around was based on gcc 8.3.0 and binutils 2.32. This patch worked fine on that.

I was going to try the patch with gcc-6.4.0 but apparently that's too old to build stock linux-6.15 (see below). Documentation/admin-guide/README.rst says I should have "at least gcc 5.1".

Anyway, I think this patch should not cause any unpleasant surprises, given that "make oldconfig" says dead code elimination is EXPERIMENTAL.

CC mm/vmscan.o
In file included from <command-line>:0:0:
mm/vmscan.c: In function 'read_ctrl_pos':
././include/linux/compiler_types.h:557:38: error: call to '__compiletime_assert_469' declared with attribute error: min(tier, 4U - 1) signedness error
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)

                                      ^
././include/linux/compiler_types.h:538:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^~~~~~

././include/linux/compiler_types.h:557:2: note: in expansion of macro '_compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'

 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^~~~~~~~~~~~~~~~~~

./include/linux/minmax.h:93:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
BUILD_BUG_ON_MSG(!__types_ok(ux, uy), \
^~~~~~~~~~~~~~~~
./include/linux/minmax.h:98:2: note: in expansion of macro '__careful_cmp_once'
__careful_cmp_once(op, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)) ^~~~~~~~~~~~~~~~~~
./include/linux/minmax.h:105:19: note: in expansion of macro '__careful_cmp'

 #define min(x, y) __careful_cmp(min, x, y)
                   ^~~~~~~~~~~~~
mm/vmscan.c:3166:37: note: in expansion of macro 'min'
  for (i = tier % MAX_NR_TIERS; i <= min(tier, MAX_NR_TIERS - 1); i++) {
                                     ^~~

make[4]: *** [scripts/Makefile.build:203: mm/vmscan.o] Error 1
make[3]: *** [scripts/Makefile.build:461: mm] Error 2
make[2]: *** [Makefile:2003: .] Error 2
make[1]: *** [/home/fthain/src/kernel.org/linux/Makefile:369: __build_one_by_one] Error 2

#5 lore raw
Quoted 4 lines · Finn Thain

Anyway, I think this patch should not cause any unpleasant surprises, given that "make oldconfig" says dead code elimination is EXPERIMENTAL.

(their emphasis).

#6 lore raw
In reply to Finn Thain

Hi Finn,

Quoted 11 lines · Finn Thain
Quoted 10 lines · Greg Ungerer
Quoted 8 lines · Daniel Palmer
Quoted 3 lines · Greg Ungerer

I notice that some other architectures (arm and powerpc) have version checks on gcc or ld in the config. Do you know if there is any version limitations for m68k here?

I'm not sure about that. I'll try to work out why they have the checks and see if that affects m68k too. I'm using GCC13 so probably new enough that most things work.

Quoted 7 lines
Quoted 3 lines

FWIW, the oldest toolchain I had lying around was based on gcc 8.3.0 and binutils 2.32. This patch worked fine on that.

I was going to try the patch with gcc-6.4.0 but apparently that's too old to build stock linux-6.15 (see below). Documentation/admin-guide/README.rst says I should have "at least gcc 5.1".

Someone forgot to update that file...
Anyway, it has just been increased again for v6.16-rc1 by Arnd in commit 118c40b7b50340bf ("kbuild: require gcc-8 and binutils-2.30").

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#7 lore raw

Hi Geert and Finn,

Quoted 19 lines · Geert Uytterhoeven

Hi Finn,

Quoted 15 lines · Finn Thain
Quoted 13 lines · Greg Ungerer
Quoted 8 lines · Daniel Palmer
Quoted 3 lines · Greg Ungerer

I notice that some other architectures (arm and powerpc) have version checks on gcc or ld in the config. Do you know if there is any version limitations for m68k here?

I'm not sure about that. I'll try to work out why they have the checks and see if that affects m68k too. I'm using GCC13 so probably new enough that most things work.

FWIW, the oldest toolchain I had lying around was based on gcc 8.3.0 and binutils 2.32. This patch worked fine on that.

Quoted 7 lines
Quoted 3 lines

I was going to try the patch with gcc-6.4.0 but apparently that's too old to build stock linux-6.15 (see below). Documentation/admin-guide/README.rst says I should have "at least gcc 5.1".

Someone forgot to update that file...
Anyway, it has just been increased again for v6.16-rc1 by Arnd in commit 118c40b7b50340bf ("kbuild: require gcc-8 and binutils-2.30").

I sort of lost track of this[0].. anyhow I looked at the other archs that have HAVE_LD_DEAD_CODE_DATA_ELIMINATION they all have different constraints.
I think we should add them if/when someone finds a toolchain that fails to build. I don't want to add some constraint for an issue that only happens on arm by mistake.

Cheers,

Daniel

0 - trying to get the Amiga m68k bootloader to build without a hacked up amigaos gcc :)

Tested-by on v1 1/1
#8 lore raw
In reply to Daniel Palmer
Quoted 11 lines · Daniel Palmer

Allow the experimental dead code elimination config to be enabled.

For my 68000 nommu config this frees up a few hundred K of memory so seems worth while.

Boot and build tested on nommu and mmu enabled configs.

Before:
Memory: 5388K/8192K available (1986K kernel code, 114K rwdata, 244K rodata, 92K init, 41K bss, 2624K reserved, 0K cma-reserved)

Quoted 5 lines

After
Memory: 5684K/8192K available (1714K kernel code, 112K rwdata, 228K rodata, 92K init, 37K bss, 2328K reserved, 0K cma-reserved)

With gcc-13.3, enabling DCE here recovered 0.5 MB of memory. Very nice! I saw no regressions in basic functionality. I tested on Aranym, Qemu and Quadra 605, including module load & unload.

Quoted 17 lines
---
 arch/m68k/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/m68k/Kconfig +1 -0
index eb5bb6d36899..11835eb59d94 100644
@@ -32,6 +32,7 @@ config M68K
 	select HAVE_ASM_MODVERSIONS
 	select HAVE_DEBUG_BUGVERBOSE
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS if !CPU_HAS_NO_UNALIGNED
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_UID16
 	select MMU_GATHER_NO_RANGE if MMU
maintainer Reviewed-by on v1 1/1
#9 lore raw
In reply to Daniel Palmer

Hi Daniel,

Quoted 11 lines · Daniel Palmer

Allow the experimental dead code elimination config to be enabled.

For my 68000 nommu config this frees up a few hundred K of memory so seems worth while.

Boot and build tested on nommu and mmu enabled configs.

Before:
Memory: 5388K/8192K available (1986K kernel code, 114K rwdata, 244K rodata, 92K init, 41K bss, 2624K reserved, 0K cma-reserved)

Quoted 5 lines

After
Memory: 5684K/8192K available (1714K kernel code, 112K rwdata, 228K rodata, 92K init, 37K bss, 2328K reserved, 0K cma-reserved)

Thanks for your patch!

Note that enabling this requires enabling CONFIG_EXPERT first, which is currently enabled in the Coldfire defconfigs, but not in the Classic defconfigs. For atari_defconfig, I see a size reduction of ca. 150 KiB (gcc 13.3.0).

i.e. will queue in the m68k tree for v6.17.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#10 lore raw
Quoted 16 lines · Geert Uytterhoeven
Quoted 15 lines · Daniel Palmer

Allow the experimental dead code elimination config to be enabled.

For my 68000 nommu config this frees up a few hundred K of memory so seems worth while.

Boot and build tested on nommu and mmu enabled configs.

Before:
Memory: 5388K/8192K available (1986K kernel code, 114K rwdata, 244K rodata, 92K init, 41K bss, 2624K reserved, 0K cma-reserved)

After
Memory: 5684K/8192K available (1714K kernel code, 112K rwdata, 228K rodata, 92K init, 37K bss, 2328K reserved, 0K cma-reserved)

Quoted 8 lines
Quoted 1 line

Thanks for your patch!

Note that enabling this requires enabling CONFIG_EXPERT first, which is currently enabled in the Coldfire defconfigs, but not in the Classic defconfigs. For atari_defconfig, I see a size reduction of ca. 150 KiB (gcc 13.3.0).

Let's share the actual figures I had saved before:

    $ bloat-o-meter vmlinux-v6.16-rc2+EXPERT{,+LD_DEAD_CODE_DATA_ELIMINATION}
    add/remove: 0/2125 grow/shrink: 10275/32 up/down: 52254/-205419 (-153165)
    [...]
    Total: Before=5277826, After=5124661, chg -2.90%
    dmesg:
    -Memory: 265412K/276480K available (4345K kernel code, 486K
rwdata, 1240K rodata, 164K init, 143K bss, 10440K reserved, 0K
cma-reserved)
    +Memory: 265616K/276480K available (4205K kernel code, 484K

rwdata, 1180K rodata, 160K init, 143K bss, 10236K reserved, 0K cma-reserved)

    gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds