Stream: t-compiler/help

Topic: codegen options not honored


Jake Goulding (Jun 13 2020 at 19:54, on Zulip):

I'm trying to get a single LLVM IR file from compiler-builtins:

RUSTFLAGS='-C codegen-units=1' rustc +local -C codegen-units=1 --crate-name compiler_builtins /Users/shep/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.32/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=llvm-ir -C opt-level=z -Clinker-plugin-lto -C debuginfo=2 --cfg 'feature="compiler-builtins"' --cfg 'feature="core"' --cfg 'feature="default"' --cfg 'feature="rustc-dep-of-std"' -C metadata=b55ef319712ad5b4 -C extra-filename=-b55ef319712ad5b4 --out-dir /Users/shep/Projects/arduino-blink/target/avr-atmega328p-new/release/deps --target /Users/shep/Projects/arduino-blink/avr-atmega328p-new.json -Zforce-unstable-if-unmarked -L dependency=/Users/shep/Projects/arduino-blink/target/avr-atmega328p-new/release/deps -L dependency=/Users/shep/Projects/arduino-blink/target/release/deps --extern core=/Users/shep/Projects/arduino-blink/target/avr-atmega328p-new/release/deps/librustc_std_workspace_core-2751de715382db4b.rmeta --cap-lints allow --cfg 'feature="unstable"' -C codegen-units=1

However, I still have many files:

% ls ./target/avr-atmega328p-new/release/deps/compiler_builtins-b55ef319712ad5b4.compiler_builtins.45srv8bc-cgu.*ll | wc
     116     116   13694

What am I missing?

simulacrum (Jun 13 2020 at 20:03, on Zulip):

see https://github.com/rust-lang/rust/pull/73136 as well

Jake Goulding (Jun 13 2020 at 22:58, on Zulip):

@simulacrum am I reading the current code correctly — the compiler hard codes the CGU amount for a crate with the name compiler-builtins?

simulacrum (Jun 13 2020 at 22:58, on Zulip):

you mean before or after that PR?

Jake Goulding (Jun 13 2020 at 22:59, on Zulip):

The new code would only affect the rustc build process, so I see how that shouldn’t affect me.

Jake Goulding (Jun 13 2020 at 22:59, on Zulip):

Before (“current” IMO since the pr hasn’t been merged)

simulacrum (Jun 13 2020 at 23:00, on Zulip):

I think no, it uses the #![compiler_builtins] attribute IIRC

Jake Goulding (Jun 13 2020 at 23:00, on Zulip):

I also have the related question of how would I get the “infinite CGU setting” when I’m compiling compiler built-ins myself for my own third tier target

simulacrum (Jun 13 2020 at 23:01, on Zulip):

on current master? I'm not sure you can without modifying the crate

simulacrum (Jun 13 2020 at 23:01, on Zulip):

and maybe not possible at all

simulacrum (Jun 13 2020 at 23:02, on Zulip):

yeah so is_compiler_builtins returns true if the crate has a crate-level #![compiler_builtins] https://github.com/rust-lang/rust/blob/06e47688bf15d0215edbe05b21603062f6d2eb5d/src/librustc_middle/ty/context.rs#L2719

Jake Goulding (Jun 13 2020 at 23:03, on Zulip):

Sorry, I’m not being clear. After this PR lands, the rust build system will set a very large CGU setting for that one crate, regardless of the passed-in value, correct?

simulacrum (Jun 13 2020 at 23:04, on Zulip):

passed-in by who?

Jake Goulding (Jun 13 2020 at 23:04, on Zulip):

Me. -C codegen

simulacrum (Jun 13 2020 at 23:05, on Zulip):

sure, yeah

Jake Goulding (Jun 13 2020 at 23:05, on Zulip):

Now, switch to my embedded use case. I use Cargo to build my crate and libcore and whatever.

Jake Goulding (Jun 13 2020 at 23:06, on Zulip):

I’m not using the rust build system.

Jake Goulding (Jun 13 2020 at 23:06, on Zulip):

How do I get “infinite CGU” for that crate when I don’t want it for other crates?

simulacrum (Jun 13 2020 at 23:07, on Zulip):

you basically have to do the same rustc wrapper trick rustbuild does I think

simulacrum (Jun 13 2020 at 23:07, on Zulip):

note though that afaict this may not really be necessary for more esoteric systems where you don't need to worry about symbol conflicts

simulacrum (Jun 13 2020 at 23:08, on Zulip):

(e.g. if you're "pure rust" then you almost certainly don't need to care about CGU count AFAICT)

Jake Goulding (Jun 13 2020 at 23:09, on Zulip):

That was going to be my next question, thank you :sweat_smile:

Jake Goulding (Jun 13 2020 at 23:09, on Zulip):

So, for today, I can just steal the deletion from that PR and rebuild Rust.

Jake Goulding (Jun 13 2020 at 23:10, on Zulip):

Then the compiler won’t set CGU behind my back.

simulacrum (Jun 13 2020 at 23:18, on Zulip):

yes, that's probably the way to go

Last update: Sep 28 2020 at 16:15UTC