Giter Site home page Giter Site logo

Comments (10)

al13n321 avatar al13n321 commented on August 11, 2024 1

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.

al13n321 avatar al13n321 commented on August 11, 2024

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.

pacak avatar pacak commented on August 11, 2024

If you pass --everything do you get both sections?

from cargo-show-asm.

al13n321 avatar al13n321 commented on August 11, 2024

(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.

pacak avatar pacak commented on August 11, 2024

--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.

al13n321 avatar al13n321 commented on August 11, 2024

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.

pacak avatar pacak commented on August 11, 2024

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.

pacak avatar pacak commented on August 11, 2024

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:

impl<'a> Label<'a> {

from cargo-show-asm.

al13n321 avatar al13n321 commented on August 11, 2024

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.

pacak avatar pacak commented on August 11, 2024

Was fixed here #112

from cargo-show-asm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.