package/jpeg-turbo: fix aarch64 build using an upstream patch
PATCH 1/1 package/jpeg-turbo: fix aarch64 build using an upstream patch
This patch is 3.2.0-8-g0da22762 in the original jpeg-turbo package, where the committer claims they can't reproduce the problem. Buildroot is currently using version 3.2.0 of the package.
The build issue I esperience with an aarch64 build (cm4 custom baseboard) is the following:
spng.c:(.text+0x4d8c): undefined reference to `__fpclassifyf'
The patch actually fixes it.
--- ...-Really-remove-gamma-correction-code.patch | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 package/jpeg-turbo/0001-libspng-Really-remove-gamma-correction-code.patch
package/jpeg-turbo/0001-libspng-Really-remove-gamma-correction-code.patch new file +109 -0
@@ -0,0 +1,109 @@ +From 0da22762971551462cfad8f0b11cfb037472a4e8 Mon Sep 17 00:00:00 2001 +From: DRC <[email protected]> +Date: Thu, 16 Jul 2026 12:09:54 -0400 +Subject: [PATCH] libspng: Really remove gamma correction code + +We really don't use it, and fpclassify() apparently introduces yet +another libm dependency in some cases (although I can't reproduce that.) + +Fixes #904 +--- + src/spng/spng.c | 20 ++++++++++++++++++-- + 1 file changed, 18 insertions(+), 2 deletions(-) + +diff --git a/src/spng/spng.c b/src/spng/spng.c +index 06249d68..aeadb67e 100644 +--- a/src/spng/spng.c ++++ b/src/spng/spng.c +@@ -353,9 +353,12 @@ struct spng_ctx + int widest_pass; + int last_pass; /* last non-empty pass */ + ++#if 0 /* libjpeg-turbo: Eliminate unused gamma correction code, which ++ introduces an unwanted libm dependency */ + uint16_t *gamma_lut; /* points to either _lut8 or _lut16 */ + uint16_t *gamma_lut16; + uint16_t gamma_lut8[256]; ++#endif + unsigned char trns_px[8]; + union spng__decode_plte decode_plte; + struct spng_sbit decode_sb; +@@ -1742,6 +1745,8 @@ static uint16_t sample_to_target(uint16_t sample, unsigned bit_depth, unsigned s + return sample; + } + ++#if 0 /* libjpeg-turbo: Eliminate unused gamma correction code, which ++ introduces an unwanted libm dependency */ + static inline void gamma_correct_row(unsigned char *row, uint32_t pixels, int fmt, const uint16_t *gamma_lut) + { + uint32_t i; +@@ -1785,6 +1790,7 @@ static inline void gamma_correct_row(unsigned char *row, uint32_t pixels, int fm + } + } + } ++#endif + + /* Apply transparency to output row */ + static inline void trns_row(unsigned char *row, +@@ -3302,7 +3308,10 @@ int spng_decode_scanline(spng_ctx *ctx, void *out, size_t len) + const struct spng_subimage *sub = ctx->subimage; + + const struct spng_ihdr *ihdr = &ctx->ihdr; ++#if 0 /* libjpeg-turbo: Eliminate unused gamma correction code, which ++ introduces an unwanted libm dependency */ + const uint16_t *gamma_lut = ctx->gamma_lut; ++#endif + unsigned char *trns_px = ctx->trns_px; + const struct spng_sbit *sb = &ctx->decode_sb; + const struct spng_plte_entry *plte = ctx->decode_plte.rgba; +@@ -3529,7 +3538,10 @@ int spng_decode_scanline(spng_ctx *ctx, void *out, size_t len) + + if(f.do_scaling) scale_row(out, width, fmt, processing_depth, sb); + ++#if 0 /* libjpeg-turbo: Eliminate unused gamma correction code, which ++ introduces an unwanted libm dependency */ + if(f.apply_gamma) gamma_correct_row(out, width, fmt, gamma_lut); ++#endif + + /* The previous scanline is always defiltered */ + void *t = ctx->prev_scanline; +@@ -3768,6 +3780,8 @@ int spng_decode_image(spng_ctx *ctx, void *out, size_t len, int fmt, int flags) + + /*if(f.same_layout && !flags && !f.interlaced) f.zerocopy = 1;*/ + ++#if 0 /* libjpeg-turbo: Eliminate unused gamma correction code, which ++ introduces an unwanted libm dependency */ + uint16_t *gamma_lut = NULL; + + if(f.apply_gamma) +@@ -3807,15 +3821,14 @@ int spng_decode_image(spng_ctx *ctx, void *out, size_t len, int fmt, int flags) + unsigned i; + for(i=0; i < lut_entries; i++) + { +-#if 0 /* libjpeg-turbo: Eliminate libm dependency */ + float c = pow((float)i / max, exponent) * max; +-#endif + float c = 0.0f; + if(c > max) c = max; + + gamma_lut[i] = (uint16_t)c; + } + } ++#endif + + struct spng_sbit *sb = &ctx->decode_sb; + +@@ -5000,7 +5013,10 @@ void spng_ctx_free(spng_ctx *ctx) + + if(!ctx->user_owns_out_png) spng__free(ctx, ctx->out_png); + ++#if 0 /* libjpeg-turbo: Eliminate unused gamma correction code, which ++ introduces an unwanted libm dependency */ + spng__free(ctx, ctx->gamma_lut16); ++#endif + + spng__free(ctx, ctx->row_buf); + spng__free(ctx, ctx->scanline_buf); +-- +2.47.3 +
Signature · 5 lines
2.47.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Hello Alessandro,
Quoted 4 lines · Alessandro Rubini
This patch is 3.2.0-8-g0da22762 in the original jpeg-turbo package, where the committer claims they can't reproduce the problem. Buildroot is currently using version 3.2.0 of the package.
Quoted 8 lines
The build issue I esperience with an aarch64 build (cm4 custom baseboard) is the following:
spng.c:(.text+0x4d8c): undefined reference to `__fpclassifyf'The patch actually fixes it.
Signed-off-by Alessandro Rubini <[email protected]>
Thanks for your patch. I was initially not able to reproduce the issue, but after digging into the autobuilder failures for this problem, I found out that the key to encounter the problem is BR2_OPTIMIZE_S=y (i.e use gcc -Os instead of our default of -O2). Do you confirm you are using BR2_OPTIMIZE_S=y in your configuration?
Overall, I can reproduce the issue with:
BR2_aarch64=y
BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_AARCH64_GLIBC_STABLE=y BR2_OPTIMIZE_S=y
BR2_PACKAGE_JPEG=y
but not with:
BR2_aarch64=y
BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_AARCH64_GLIBC_STABLE=y BR2_PACKAGE_JPEG=y
Do we understand why the issue happens with -Os but not -O2 ?
Quoted 6 lines
package/jpeg-turbo/0001-libspng-Really-remove-gamma-correction-code.patch new file +0
-0
package/jpeg-turbo/0001-libspng-Really-remove-gamma-correction-code.patch line 9
Quoted 9 lines
package/jpeg-turbo/0001-libspng-Really-remove-gamma-correction-code.patch new file +9
-0@@ -0,0 +1,109 @@ +From 0da22762971551462cfad8f0b11cfb037472a4e8 Mon Sep 17 00:00:00 2001 +From: DRC <[email protected]> +Date: Thu, 16 Jul 2026 12:09:54 -0400 +Subject: [PATCH] libspng: Really remove gamma correction code + +We really don't use it, and fpclassify() apparently introduces yet +another libm dependency in some cases (although I can't reproduce that.) + +Fixes #904
We require all patches added in Buildroot to have:
- An "Upstream:" tag that points to the upstream commit, PR or patch submission (in your case, commit)
- A "Signed-off-by:" tag from the person who introduced the patch into Buildroot, i.e you.
Could you adjust this, together with hopefully some explanation on why -Os triggers the issue and not -O2?
Thanks a lot!
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 2 lines · Thomas Petazzoni
Could you adjust this, together with hopefully some explanation on why -Os triggers the issue and not -O2?
Ah, and also, in your commit message, you can add a reference to the autobuilder issue being fixed, as follows:
Fixes:
https://autobuild.buildroot.net/results/d5321270034c2f14b613d69519e562ec16135ac0/
Thanks a lot!
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot