Comments (10)
If you pass
--everything
do you get both sections?
Yes. Here's the whole .s
file (from RUSTFLAGS="--emit asm" cargo build
): https://pastebin.com/gDaEZBcu . There are "_ZN4rust4main17h90585feb19c01afdE
" and "?dtor$1@?0?_ZN4rust4main17h90585feb19c01afdE@4HA
"
from cargo-show-asm.
This doesn't seem to be a matter of having multiple functions with the same name in the binary:
$ cargo asm --dev rust
[...]
Try one of those by name or a sequence number
0 "rust::main" [112]
1 "std::sys_common::backtrace::__rust_begin_short_backtrace" [55]
shows only one main
function
("rust" is just the name of my package, could be any other string, sorry it's confusing)
(Side note: cargo asm --dev main 1234567
produces the same output with no indication that "1234567" is nonsense. Would be nice to error out instead.)
from cargo-show-asm.
If you pass --everything
do you get both sections?
from cargo-show-asm.
(Oh, and here's the --everything
output, in case it's significantly different from the .s
file: https://pastebin.com/nR5zhdKY )
from cargo-show-asm.
--everything
should be the same as .s
but with syntax highlight if available and demangled names. Will take a look, not sure what's going on. Windows is strange sometimes :)
from cargo-show-asm.
Looking into it a little, I'm struggling to figure out how exactly these .seh_*
pseudos are organized.
The relevant parts of the .s file appear to be (paraphrased a little), for a function "foo":
.def foo
.section .text,...,foo
.foo:
.Lfunc_begin1337:
.seh_proc foo
<actual code>
.seh_handlerdata
.section .text,...,foo <--- wtf?
.seh_endproc
.def "?dtor$foo"
"?dtor$foo":
.seh_proc "?dtor$foo"
<some uninteresting exception handling code>
<possibly some more dtor blocks like above>
.Lfunc_end1337
So, a simple solution would be to not make find_items()
ignore consecutive duplicate .section directives. Then the output will have both the function's main code and all the dtor blocks.
(I don't really know how correct this is, because I don't understand what these duplicate .section directives are even supposed to mean. E.g. maybe the second .section should be ignored not because it's a duplicate but because it's inside a .seh_proc/.seh_endproc pair?)
I'll send a PR for this later, if this sounds reasonable.
There are apparently lots of these dtor blocks in less trivial code. E.g. this 6-line function produced 15 dtor blocks: https://pastebin.com/UrjwgY6w . Presumably because of inlining, but still! Would be pretty annoying if they're all included in the cargo-show-asm output by default. So I would also add a hack making find_items()
treat the first .seh_endproc
as the end of function, instead of waiting for .Lfunc_end
.
But is this different on other platforms? Do they also generate lots of duplicate code for panic unwinding depending on where the panic happened? Or is it more concise somehow? Is it included in the cargo-show-asm output too? Maybe I'll test it on Mac OS later.
EDIT: On a second look, in that example with 15 dtor blocks, their total size is still less than the body of the function, and they're kind of out of the way (at the end), so probably better to not do anything about this and print them all.
from cargo-show-asm.
Do you ever want to look at contents of those dtor blocks? Displaying 15 of them is not a big deal. cargo-show-asm
collapses items with identical names (but different hashes) like this:
17 "<T as serde::de::Expected>::fmt" [7, 7, 7, 7, 7, 7, 7, 7, 16, 7, 7, 12, 7, 7, 7, 7, 12, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]
^ there's a bunch of <T as serde::de::Expected>::fmt
items, those numbers are showing their sizes in lines and you can pick which one you want to look at by passing a name + index.
Does it makes sense to do something similar for destructors?
from cargo-show-asm.
seh_*
is used for structural exception handling and seems to be windows specific, at least the example you have in the ticket generates nothing like that on Linux.
There's a list of supported commands here: https://sourceware.org/legacy-ml/binutils/2009-08/msg00193.html
As far as I can see problem comes from cargo-show-asm
not recognizing things like
"?dtor$3@?0?_ZN4rust4main17h90585feb19c01afdE@4HA":
as labels and mangling previous definition and if we start parsing them - they will automagically show up in parsed names.
Parsing code lives here:
cargo-show-asm/src/asm/statements.rs
Line 172 in 1596f47
from cargo-show-asm.
As far as I can see problem comes from cargo-show-asm not recognizing things like
"?dtor$3@?0?_ZN4rust4main17h90585feb19c01afdE@4HA": as labels and mangling previous definition and if we start parsing them - they will automagically show up in parsed names.
For each function there's only one pair .Lfunc_begin - .Lfunc_end, surrounding both the main body of the function and all the dtor blocks. Would it make sense to treat all the code between .Lfunc_begin and .Lfunc_end as one block of code - the code of the function? I'm guessing this is in line with the codegen's intention, and it seems more useful (I'd rather see all of the function's code at once than request the dtor blocks one by one). Then we don't have to recognize or separate out the dtor blocks (labels, seh_* directives, any of that) - they can be considered function's internal implementation details. That's how my PR interprets things.
from cargo-show-asm.
Was fixed here #112
from cargo-show-asm.
Related Issues (20)
- `sample` test case is broken with 1.75 HOT 12
- Add use a separate library to implement syntax highlight for llvm/mir/asm
- Wrong path used for rustc sources HOT 10
- Automate release process
- --rust flag shows code from libstd HOT 4
- Function selection via index broken on v0.2.24 to v0.2.28 HOT 6
- Option to include called functions (to some depth) HOT 6
- Install fails with rustc 1.74.0 HOT 3
- [Bugfix]: release-plz workflow - ERROR failed to update packages HOT 3
- color output can be very difficult to read on dark backgrounds HOT 1
- `--simplify` removes inline assembly HOT 5
- Debug info included by default in 0.2.33 HOT 1
- Missing/incorrect line information HOT 6
- An easier way to compare different versions
- Missed no_mangle symbol in no_std/no_main Windows code HOT 10
- On 32bit Windows no_mangle names needs stripping
- Support `rustc_codegen_cranelift` HOT 2
- panic with message "DWARF file refers to an undefined location" HOT 5
- `cargo-asm` panics with `No cdylib?` when called in a `["lib", "cdylib"]` wasm project HOT 2
- Does not work on default new library HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cargo-show-asm.