Bug 2184553 - Literal "%_package_note_flags" gets included in RUSTFLAGS if %_package_note_flags is undefined as recommended in macros.package-notes-srpm
Summary: Literal "%_package_note_flags" gets included in RUSTFLAGS if %_package_note_f...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: package-notes
Version: rawhide
Hardware: All
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Zbigniew Jędrzejewski-Szmek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-04-05 01:38 UTC by Adam Williamson
Modified: 2023-05-25 01:11 UTC (History)
8 users (show)

Fixed In Version: package-notes-0.5-7.fc37 package-notes-0.5-8.fc38
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-05-25 00:59:53 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Adam Williamson 2023-04-05 01:38:46 UTC
It's not possible to build Firefox on Rawhide currently, because this happens at the start of %build:

+ RUSTFLAGS='-Copt-level=3 -Cdebuginfo=2 -Ccodegen-units=1 -Cforce-frame-pointers=yes -Clink-arg=-Wl,-z,relro -Clink-arg=-Wl,-z,now -Clink-arg=%_package_note_flags --cap-lints=warn'

note the literal "-Clink-arg=%_package_note_flags" there. The compile fails early with an error caused by that:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/usr/lib/rustlib/aarch64-unknown-linux-gnu/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin" VSLANG="1033" "cc" "/tmp/rustcikCLpX/symbols.o" "/tmp/cargo-installyFVADQ/release/build/getrandom-34a1f1ba694ad49d/build_script_build-34a1f1ba694ad49d.build_script_build.3c12eb4c-cgu.0.rcgu.o" "/tmp/cargo-installyFVADQ/release/build/getrandom-34a1f1ba694ad49d/build_script_build-34a1f1ba694ad49d.3v5qnvgc1ty3l6d1.rcgu.o" "-Wl,--as-needed" "-L" "/tmp/cargo-installyFVADQ/release/deps" "-L" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd-8acfd703d435cdb2.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libpanic_unwind-1a8b32fb2cb86a12.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libobject-ab4f8839a2db893e.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libmemchr-3105431385bf5e5c.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libaddr2line-b9581ca22fc44fe4.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libgimli-bb973365fcb85796.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_demangle-b6a893cda6fbdcc5.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd_detect-13eab766285f02d9.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libhashbrown-cfcd372989758c04.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libminiz_oxide-4ddd810e85dabb0d.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libadler-d71966f68041b84b.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-ee2c54e4bbe147c4.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libunwind-e309eb7950732fd3.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcfg_if-8ccfe3e7eb560429.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/liblibc-68acc36bf75feacf.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/liballoc-b255fa7067ca8fe7.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_std_workspace_core-f2ff77af1dbe49bb.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcore-081a28c5f255ae1e.rlib" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-02ce3881e62c56e9.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/tmp/cargo-installyFVADQ/release/build/getrandom-34a1f1ba694ad49d/build_script_build-34a1f1ba694ad49d" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs" "-Wl,-z,relro" "-Wl,-z,now" "%_package_note_flags"
  = note: /usr/bin/ld: cannot find %_package_note_flags: No such file or directory
          collect2: error: ld returned 1 exit status

I believe this is being caused by /usr/lib/rpm/macros.d/macros.rust , specifically line 47:

  %[0%{?_package_note_status} ? "-Clink-arg=%_package_note_flags" : ""]

clearly %_package_note_flags is meant to be expanded there, but it is not getting expanded. But I don't know, off the top of my head, how to fix that in that specific case...

Comment 1 Adam Williamson 2023-04-05 03:01:50 UTC
Thanks to alebastr from IRC for the explanation:

alebastr
`%[0%{?_package_note_status} ? "-Clink-arg=%_package_note_flags" : ""]` in macros.rust doesn't work with the opt-out mechanism suggested in macros.package-notes-srpm
alebastr
i.e. firefox.spec undefines _flags, but _status is still 1

I can have firefox.spec also undefine _status, but it sounds like the mechanism needs rethinking...

Comment 2 Fabio Valentini 2023-04-05 06:49:28 UTC
This is a bug in Mozilla's bespoke build system. Setting RUSTFLAGS is the canonical way of setting rustc fflags (similar to CFLAGS etc.), but their build system chokes on it for some reason. The only workaround I know of is to "unset RUSTFLAGS" (which was also necessary in thunderbird).

This is also the reason why Rust code in Firefox, Thunderbird, mozjs* etc. is built in a way that doesn't honor default Fedora compiler flags ...

Comment 3 Miro Hrončok 2023-04-05 07:28:10 UTC
I've heard that before, but honestly, a literal macro in the falgs can hardly be Firefox fault. The comment in https://src.fedoraproject.org/rpms/package-notes/blob/rawhide/f/macros.package-notes-srpm says the way Firefox uses to opt-out is correct. Hence I really think %build_rustflags need a fix.

Using the status to see if we should set the flags is not enough, because the way the opt-out works leaves the status set it seems.

Either %build_rustflags needs to check if the %_package_note_flags macro is defined before using it, or better yet, %_package_note_status should do the check.

Comment 4 Fabio Valentini 2023-04-05 07:36:17 UTC
Sure, but that's a different problem, and solving it won't fix the Firefox build. It chokes when RUSTFLAGS is set at all, even if there's no unexpanded macros in there.

Comment 5 Miro Hrončok 2023-04-05 09:05:20 UTC
Ack.

---


Back to the problem reported here.

Default (name has to be set, consider it implementation detail):

<mock-chroot> sh-5.2# rpm --define 'name xxx' --eval '%build_rustflags'
-Copt-level=3 -Cdebuginfo=2 -Ccodegen-units=1 -Cforce-frame-pointers=yes -Clink-arg=-Wl,-z,relro -Clink-arg=-Wl,-z,now -Clink-arg=-specs=/usr/lib/rpm/redhat/redhat-package-notes --cap-lints=warn

The documented opt-out:

<mock-chroot> sh-5.2# rpm --define 'name xxx' --undefine '_package_note_flags' --eval '%build_rustflags'
-Copt-level=3 -Cdebuginfo=2 -Ccodegen-units=1 -Cforce-frame-pointers=yes -Clink-arg=-Wl,-z,relro -Clink-arg=-Wl,-z,now -Clink-arg=%_package_note_flags --cap-lints=warn

Bam!


Change in /usr/lib/rpm/macros.d/macros.package-notes-srpm:

-%_package_note_status   %[0%{?_package_note_file:1} && 0%{?name:1} && "%_target_cpu" != "noarch" && "%{toolchain}" != "clang" ? 1 : 0]
+%_package_note_status   %{!?_package_note_flags:0}%{?_package_note_flags:%[0%{?_package_note_file:1} && 0%{?name:1} && "%_target_cpu" != "noarch" && "%{toolchain}" != "clang" ? 1 : 0]}

Default:

<mock-chroot> sh-5.2# rpm --define 'name xxx' --eval '%build_rustflags'
-Copt-level=3 -Cdebuginfo=2 -Ccodegen-units=1 -Cforce-frame-pointers=yes -Clink-arg=-Wl,-z,relro -Clink-arg=-Wl,-z,now -Clink-arg=-specs=/usr/lib/rpm/redhat/redhat-package-notes --cap-lints=warn

<mock-chroot> sh-5.2# rpm --define 'name xxx' --eval '%build_ldflags'
-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes 


Opt-out:

<mock-chroot> sh-5.2# rpm --define 'name xxx' --undefine '_package_note_flags' --eval '%build_rustflags'
-Copt-level=3 -Cdebuginfo=2 -Ccodegen-units=1 -Cforce-frame-pointers=yes -Clink-arg=-Wl,-z,relro -Clink-arg=-Wl,-z,now --cap-lints=warn

<mock-chroot> sh-5.2# rpm --define 'name xxx' --undefine '_package_note_flags' --eval '%build_ldflags'
-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1

Comment 6 Miro Hrončok 2023-04-05 09:09:11 UTC
Alternatively, %build_rustflags can check if %_package_note_flags is not empty/undefined to determine if it should use it instead of checking the status macro. But I belive that what I propose is the proper place to fix this. The status should be 0 when %_package_note_flags was undefined.

Comment 7 Adam Williamson 2023-04-05 14:52:41 UTC
Fabio: I'm tracking the "It chokes when RUSTFLAGS is set at all" part elsewhere, currently in https://bugzilla.redhat.com/show_bug.cgi?id=2184549 but I'll file a new bug now. (A more accurate description is "It chokes when RUSTFLAGS is set to a string with a comma in it").

To be clear, this bug is now for making %build_rustflags handle %_package_note_flags being undefined, as recommended at https://src.fedoraproject.org/rpms/package-notes/blob/rawhide/f/macros.package-notes-srpm#_10 .

Comment 8 Fedora Update System 2023-05-20 19:00:22 UTC
FEDORA-2023-e9e51c65b5 has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2023-e9e51c65b5

Comment 9 Fedora Update System 2023-05-20 19:00:23 UTC
FEDORA-2023-88d0260bcb has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2023-88d0260bcb

Comment 10 Fedora Update System 2023-05-21 03:35:50 UTC
FEDORA-2023-88d0260bcb has been pushed to the Fedora 37 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-88d0260bcb`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-88d0260bcb

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 11 Fedora Update System 2023-05-21 03:50:05 UTC
FEDORA-2023-e9e51c65b5 has been pushed to the Fedora 38 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-e9e51c65b5`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-e9e51c65b5

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 12 Fedora Update System 2023-05-25 00:59:53 UTC
FEDORA-2023-88d0260bcb has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 13 Fedora Update System 2023-05-25 01:11:14 UTC
FEDORA-2023-e9e51c65b5 has been pushed to the Fedora 38 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.