Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 940923 - media-libs/fontconfig: oversized font in sci-calculators/qalculate-gtk when built with sys-devel/gcc:14 and -O3 -flto
Summary: media-libs/fontconfig: oversized font in sci-calculators/qalculate-gtk when b...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: lto 915000
  Show dependency tree
 
Reported: 2024-10-06 07:07 UTC by Nicu Borta
Modified: 2024-10-12 23:20 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge--info.txt,6.07 KB, text/plain)
2024-10-06 07:07 UTC, Nicu Borta
Details
Build log (media-libs:fontconfig-2.15.0:20241006-065725.log,50.31 KB, text/x-log)
2024-10-06 07:09 UTC, Nicu Borta
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicu Borta 2024-10-06 07:07:39 UTC
Created attachment 904948 [details]
emerge --info

Building fontconfig with lto causes fonts to be oversized under some cases for sci-calculators/qalculate-gtk.

See: https://github.com/Qalculate/qalculate-gtk/issues/550
Comment 1 Nicu Borta 2024-10-06 07:09:39 UTC
Created attachment 904949 [details]
Build log
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-06 07:30:54 UTC
Ha, I started to look at this and ran into bug 940927 which I'll need to fix first.
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-06 07:58:55 UTC
Could you give me some exact steps on what to do after opening qalculate-gtk? I can't reproduce it yet.
Comment 4 Nicu Borta 2024-10-06 08:22:57 UTC
(In reply to Sam James from comment #3)
> Could you give me some exact steps on what to do after opening
> qalculate-gtk? I can't reproduce it yet.

1. In the top pane, input an expression that would be rendered using superscripts/subscripts (e.g. 2^2);
2. Observe in the pane below, the superscript/subscript is rendered at a much larger font that the base;
3. Emerge media-libs/fontconfig without lto and redo 1-2, observe that the superscript/subscript is rendered correctly.

I can replicate this on 2 separate systems. Might only be an issue on wayland.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-06 08:28:06 UTC
Thanks, it turns out I can reproduce with GCC 14 and not trunk. I will look more later.
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-06 08:35:29 UTC
It's not required, but if you can find any other testcases, that might be useful. Even better would be the testsuite of something using fontconfig failing.

But again, not needed, it would just speed up some of the investigation later (as having to check graphically is a pain).
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-07 14:24:08 UTC
It becomes latent on trunk with r15-571-g1e0ae1f52741f7. Reverting it on trunk breaks it there too. I'll bisect for the break next, releases/gcc-13 is fine.
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-07 15:42:35 UTC
Introduced by r14-6536-gcd794c39610177 (sccp).
Comment 9 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-08 15:24:26 UTC
FcDefaultSubstitute gets a bogus value from FcPatternIterGetValues/FcValueCanonicalize, so in FcDefaultSubstitute, this trap fires:

	scale = 1.0;
    if (FcPatternObjectGetDouble (pattern, FC_DPI_OBJECT, 0, &dpi) != FcResultMatch)
		dpi = 75.0;

    if (FcPatternFindObjectIter (pattern, &iter, FC_PIXEL_SIZE_OBJECT)) {
    	FcValueListPtr l = FcPatternIterGetValues (pattern, &iter);
		v = FcValueCanonicalize (&l->value);

		size = v.u.d;
		printf("size-before-scaling=%f\n", size);

		size = size / dpi * 72.0 / scale;
		printf("dpi=%f\n", dpi);
		printf("scale=%f\n", scale);
		printf("size=%f\n", size);
    }

    (void) FcPatternObjectDel (pattern, FC_SIZE_OBJECT);

    if (fabs(size - 60.f) < 0.01) {
        __builtin_trap();
    }

Trying to separate it out more..
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-08 15:41:18 UTC
I think FC is wrong.

This fixes it:
```
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -253,7 +253,7 @@ typedef enum _FcValueBinding {

 typedef struct _FcPattern   FcPattern;

-typedef struct _FcPatternIter {
+typedef struct __attribute__((may_alias)) _FcPatternIter {
     void *dummy1;
     void *dummy2;
 } FcPatternIter;
```

They pun betewen _FcPatternPrivateIter and _FcPatternIter:

typedef struct _FcPatternPrivateIter {
    FcPatternElt *elt;
    int           pos;
} FcPatternPrivateIter;
Comment 12 Larry the Git Cow gentoo-dev 2024-10-08 16:06:25 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c9130151b56e3be1adc76e84df0e9dcd1a4bd3e3

commit c9130151b56e3be1adc76e84df0e9dcd1a4bd3e3
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-10-08 16:05:00 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-10-08 16:05:47 +0000

    media-libs/fontconfig: fix aliasing violation
    
    We had a report of GCC 14 with -O3 -flto causing wrong font
    sizes with fontconfig (showing up in qalculate-gtk).
    
    It turns out to be because _FcPatternIter and _FcPatternPrivateIter
    are punned between which violates strict-aliasing rules, which
    manifested in FcDefaultSubstitute getting a bogus value from
    FcValueCanonicalize for size.
    
    Mark the bad struct as may_alias to fix that.
    
    Closes: https://bugs.gentoo.org/940923
    Signed-off-by: Sam James <sam@gentoo.org>

 .../files/fontconfig-2.15.0-aliasing.patch         |  53 +++++
 media-libs/fontconfig/fontconfig-2.15.0-r1.ebuild  | 234 +++++++++++++++++++++
 2 files changed, 287 insertions(+)
Comment 13 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-08 16:06:51 UTC
Thank you for the report!
Comment 14 Nicu Borta 2024-10-09 05:01:55 UTC
Thank you for your work in fixing this!