Open glandium opened 6 years ago
I have no clue how this can be improved, but surely one of our enlightened people have.
Cc @rust-lang/wg-codegen
I am not sure what the proposed improvement is here, either. On recent versions, everything seems much different, see this Godbolt:
.L__unnamed_6:
.L__unnamed_1:
.ascii "called `Option::unwrap()` on a `None` value"
.L__unnamed_7:
.ascii "/app/example.rs"
.L__unnamed_2:
.quad .L__unnamed_7
.asciz "\017\000\000\000\000\000\000\000\002\000\000\000\005\000\000"
.L__unnamed_3:
.ascii "an expectation"
.L__unnamed_4:
.quad .L__unnamed_7
.asciz "\017\000\000\000\000\000\000\000\006\000\000\000\005\000\000"
.L__unnamed_8:
.ascii "a print"
.L__unnamed_5:
.quad .L__unnamed_8
.asciz "\007\000\000\000\000\000\000"
Nonzero number of quads, but less. Everything in the actual code seems to be using rip
-relative addressing with lea
, and it loads both things at a time before proceeding.
However, the dizzying array of stuff with the full-blown panic!
sections remains quite significant in this one, but that may be because of trying to minimize the impact of the panic!
call itself:
example::panics:
push rax
call std::panicking::begin_panic
ud2
.L__unnamed_3:
.quad core::ptr::drop_in_place<&str>
.asciz "\020\000\000\000\000\000\000\000\b\000\000\000\000\000\000"
.quad <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::take_box
.quad <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get
.L__unnamed_4:
.quad core::ptr::drop_in_place<&str>
.asciz "\020\000\000\000\000\000\000\000\b\000\000\000\000\000\000"
.quad <T as core::any::Any>::type_id
.L__unnamed_1:
.ascii "a panic"
.L__unnamed_5:
.ascii "/app/example.rs"
.L__unnamed_2:
.quad .L__unnamed_5
.asciz "\017\000\000\000\000\000\000\000\002\000\000\000\005\000\000"
I hesitate to pronounce things as better or worse now, or to assert the string relocations are necessarily bad or good.
Consider the following code:
This generates the following:
The quads under
.Lref.2
correspond to (pointer, length) pairs for both strings emitted by unwrap(). The way they are stored looks related to the call convention forcore::panicking::panic
, which looks like it just wants a pointer to a buffer containing 2 &str and 2 integers. The problem with this is that each of those pointers need relocations in the final position independent binary. And in ELF, those are large: each relocation is 2 (on 32-bits) or 3 (on 64-bits) words, so 24 bytes on 64-bits. Per string.The same kind of thing happens with
panic!
:I'll skip the assembly for the code itself, but the data looks like:
Do note that there is no reference to
str.4
, the corresponding (pointer, length) is actually created from code in that case:And the same again for
print!
:generating this data:
A counter example is
Option::expect
:which generates: