Closed Bug 1753402 Opened 4 years ago Closed 4 years ago

Firefox fails to build with rust rustc 1.58.1 (Fedora 36) error[E0740]: unions may not contain fields that need dropping

Categories

(Firefox Build System :: General, defect)

defect

Tracking

(firefox97 fixed, firefox98 fixed)

RESOLVED FIXED
98 Branch
Tracking Status
firefox97 --- fixed
firefox98 --- fixed

People

(Reporter: stransky, Assigned: emilio)

Details

Attachments

(3 files)

Firefox 96.0.3 fails to build on Fedora 36 (rust 1.58.1) with

5:34.41 error[E0740]: unions may not contain fields that need dropping

5:34.41 Running CARGO=/usr/bin/cargo CARGO_CRATE_NAME=viaduct CARGO_MANIFEST_DIR=/home/komat/rpmbuild/BUILD/firefox-96.0.3/third_party/rust/viaduct CARGO_PKG_AUTHORS='Thom Chiovoloni <tchiovoloni@mozilla.com>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MPL-2.0 CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=viaduct CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/release/deps:/usr/lib' /usr/bin/rustc --crate-name viaduct --edition=2018 /home/komat/rpmbuild/BUILD/firefox-96.0.3/third_party/rust/viaduct/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=2 -C panic=abort -C embed-bitcode=no --cfg 'feature="default"' -C metadata=739bfa36e003c8db -C extra-filename=-739bfa36e003c8db --out-dir /home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C linker=/home/komat/rpmbuild/BUILD/firefox-96.0.3/build/cargo-linker -L dependency=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps -L dependency=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/release/deps --extern ffi_support=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps/libffi_support-380d86c20e4a9997.rmeta --extern log=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps/liblog-6582ada378cf50c4.rmeta --extern once_cell=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps/libonce_cell-2f7119dcc8f78c60.rmeta --extern prost=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps/libprost-d624e9d5f8584670.rmeta --extern prost_derive=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/release/deps/libprost_derive-e7e354ecd2c2ccf6.so --extern serde=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps/libserde-c79671ed8ebc0be5.rmeta --extern serde_json=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps/libserde_json-7cc1275ecaf8c471.rmeta --extern thiserror=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps/libthiserror-6463aac5a9cb8499.rmeta --extern url=/home/komat/rpmbuild/BUILD/firefox-96.0.3/objdir/x86_64-unknown-linux-gnu/release/deps/liburl-480aee27e43f6f85.rmeta --cap-lints warn -C debuginfo=2 --cap-lints warn -Cembed-bitcode=yes -C codegen-units=1

Thanks for the report!
I've got a couple questions:

  • How does your mozconfig look? If you build 96.0.3 without a mozconfig, does it work?
  • If you run the provided rustc command as shown in the error message as a standalone command, does it still fail?
Flags: needinfo?(stransky)

There is no union in viaduct. I don't think the command in comment 0 is the one that failed. Can you paste more context around the error?

Can't reproduce, even with --enable-warnings-as-errors.

i have this too with gcc 9

my ugly script:

set -e
cat > unstable.chroot/root/run.sh <<GLOBALEOF
set -e
set -v
echo "deb http://deb.debian.org/debian experimental main">/etc/apt/sources.list.d/exp.list
apt-get update
apt-get install -y gcc-9 g++-9 mercurial -t experimental
if test ! -d /root/firefox-gcc-last; then
hg clone https://hg.mozilla.org/mozilla-central/ /root/firefox-gcc-last
fi
cd /root/firefox-gcc-last


cat .mozconfig

cat > .mozconfig << EOF
ac_add_options --enable-debug
ac_add_options --enable-optimize=-O2
ac_add_options --enable-warnings-as-errors
mk_add_options AUTOCLOBBER=1
ac_add_options --enable-bootstrap
ac_add_options --without-sysroot
ac_add_options --without-wasm-sandboxed-libraries


CC=gcc-9
CXX=g++-9
export CXXFLAGS="-O2 -DGLIB_DISABLE_DEPRECATION_WARNINGS"
export CFLAGS="-O2 -DGLIB_DISABLE_DEPRECATION_WARNINGS"
export CXXFLAGS="-O2 -Wno-error=class-memaccess -Wno-error=format-overflow -Wno-error=stringop-truncation -Wno-stringop-overflow -Wno-error=attributes -Wno-error=deprecated-copy -Wno-error=pessimizing-move -Wno-error=type-limits"
export CFLAGS="-O2 -Wno-error=class-memaccess -Wno-error=format-overflow -Wno-error=stringop-truncation -Wno-stringop-overflow -Wno-error=type-limits"
EOF

./mach clobber||true
hg pull -u
hg revert .
hg update -r default
export PATH=/root/.cargo/bin/:$PATH

hg revert .
rustup update
cargo install cbindgen --force


sed -i -e "s|-Wno-unreachable-code-return||g"  security/sandbox/linux/moz.build 
cat security/sandbox/linux/moz.build 


./mach  --log-no-times  build #-v
rm -rf obj-x86_64-pc-linux-gnu/
hg revert security/sandbox/linux/moz.build

GLOBALEOF

PATH_CHROOT=/var/lib/jenkins/workspace/firefox-gcc-9-last/unstable.chroot

sudo chroot $PATH_CHROOT/ ./root/run.sh 
exit 0

Relevant part of the log:

error[E0740]: unions may not contain fields that need dropping
--> /root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/build/gecko-profiler-1d5db7af5b183b3f/out/gecko/bindings.rs:5:72010

So this comes from code generated by cbindgen. What version are you using?

Actually, it comes from rust-bindgen, which is in-tree...

Can't reproduce with the script in comment 5.

Yes, the command from 0 doesn't look relevant, sorry for the confusion.

Flags: needinfo?(stransky)
Attached file build log

There's a build log from repeated run....hope it helps.

Seems to be something in a system libstdc++ header that rust-bindgen doesn't handle properly... the version we're using was released more than 1 year ago. Emilio, do you know if this might have been fixed in a newer version?

Flags: needinfo?(emilio)

This is Fedora 36 system (not released yet) and the build error happened after recent update (unfortunately I can't say which package). Also this is a distro build with system libraries, not with bootstrapped ones.

Martin, I'm on a Fedora Rawhide machine, I tried to repro with ac_add_options --disable-bootstrap, but couldn't. Do you have a way for me to potentially reproduce?

If not, could you attach the contents of this file? /root/firefox-gcc-last/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/build/gecko-profiler-1d5db7af5b183b3f/out/gecko/bindings.rs

Flags: needinfo?(stransky)

I found the relevant STL code and can reproduce a similar failure with:

template <typename _Tp, typename _Alloc>
struct _Vector_base {
  union _Storage {
    constexpr _Storage() : _M_byte() {}
    ~_Storage() {}
    _Storage& operator=(const _Storage&) = delete;
    unsigned char _M_byte;
    _Tp _M_val;
  };
};

Which generates some rust code like:

/* automatically generated by rust-bindgen 0.59.2 */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _Vector_base {
    pub _address: u8,
}
#[repr(C)]
pub union _Vector_base__Storage<_Tp> {
    pub _M_byte: ::std::os::raw::c_uchar,
    pub _M_val: _Tp,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_Tp>>,
}
Flags: needinfo?(emilio)

We don't use unions in the bindings, and rust is very picky with what
you can put on untagged unions, so disable them for now.

Assignee: nobody → emilio
Status: NEW → ASSIGNED

Martin, can you confirm the patch above fixes the build for you?

I filed https://github.com/rust-lang/rust-bindgen/issues/2157 to track this bindgen issue.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #15)

Created attachment 9262299 [details]
Bug 1753402 - Disable untagged union in Gecko profiler bindings. r=canaltinova,gerald

We don't use unions in the bindings, and rust is very picky with what
you can put on untagged unions, so disable them for now.

Another thing that might be a bindgen bug to file is why are these stl type bindings generated, when what's requested is opaque types for std::string and std::vector?

Flags: needinfo?(emilio)

Yeah, but the underlying type name here is probably different. Hard to say without being able to reproduce.

Flags: needinfo?(emilio)
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 98 Branch

Thanks, I'll check that with Firefox 97 builds there.

(In reply to Andreea Pavel [:apavel] from comment #20)

https://hg.mozilla.org/mozilla-central/rev/9d70daa2857f

Does this fix exist also for FirefoxESR?

Comment on attachment 9262299 [details]
Bug 1753402 - Disable untagged union in Gecko profiler bindings. r=canaltinova,gerald

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: One-liner build fix
  • User impact if declined: none
  • Fix Landed on Version:
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Build-only

Beta/Release Uplift Approval Request

  • User impact if declined: One-liner build fix.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: none
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Build-only
  • String changes made/needed: none
Attachment #9262299 - Flags: approval-mozilla-release?
Attachment #9262299 - Flags: approval-mozilla-esr91?

That seems to help, Thanks.

Flags: needinfo?(stransky)

Comment on attachment 9262299 [details]
Bug 1753402 - Disable untagged union in Gecko profiler bindings. r=canaltinova,gerald

Approved for 97.0.1 and 91.7esr.

Attachment #9262299 - Flags: approval-mozilla-release?
Attachment #9262299 - Flags: approval-mozilla-release+
Attachment #9262299 - Flags: approval-mozilla-esr91?
Attachment #9262299 - Flags: approval-mozilla-esr91+

Comment on attachment 9262299 [details]
Bug 1753402 - Disable untagged union in Gecko profiler bindings. r=canaltinova,gerald

Actually, this file doesn't exist on ESR91. Looks like it landed during the Fx92 development cycle. Feel free to attach a branch-specific patch and request approval on it if there's a different spot that needs fixing there.

Attachment #9262299 - Flags: approval-mozilla-esr91+

(In reply to Ryan VanderMeulen [:RyanVM] from comment #26)

Comment on attachment 9262299 [details]
Bug 1753402 - Disable untagged union in Gecko profiler bindings. r=canaltinova,gerald

Actually, this file doesn't exist on ESR91. Looks like it landed during the Fx92 development cycle. Feel free to attach a branch-specific patch and request approval on it if there's a different spot that needs fixing there.

Please, we need support for ESR91 too; Firefox 91ESR and all derived cannot be built against Rust-1.58.1 currently

(In reply to Antonio T. from comment #28)

(In reply to Ryan VanderMeulen [:RyanVM] from comment #26)
Please, we need support for ESR91 too; Firefox 91ESR and all derived cannot be built against Rust-1.58.1 currently

What is the build failure? It can't be the same bug, please file a separate bug and cc / ni? me please?

Flags: needinfo?(trpost)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #29)

(In reply to Antonio T. from comment #28)

(In reply to Ryan VanderMeulen [:RyanVM] from comment #26)
Please, we need support for ESR91 too; Firefox 91ESR and all derived cannot be built against Rust-1.58.1 currently

What is the build failure? It can't be the same bug, please file a separate bug and cc / ni? me please?

You're right, it's not a Rust dependent issue. Probably it's related to the bug #1754752
Sorry.

Flags: needinfo?(trpost)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: