Git Product home page Git Product logo

Comments (10)

cfcohen avatar cfcohen commented on September 16, 2024

Yes. Arrays of objects were known to be a topic that requires improvement. Are you able to determine exactly what we don't handle? I assume we found almost nothing in this particular case. I would think that our code should by default treat it like a single instance of an object.

It's quite likely that at least part of the problem is that "Foo()" is a pretty thin class. Try adding some features to the class that will make OOAnalyzer's job easier, like a virtual method and an invocation of that method then see if we do better. That should help separate what parts of the problem are related to object arrays versus other problems in OOAnalyzer.

We might be missing the name for the new[] operator here:

https://github.com/cmu-sei/pharos/blob/master/libpharos/ooanalyzer.cpp#L294

Or the hash here:

https://github.com/cmu-sei/pharos/blob/master/libpharos/ooanalyzer.cpp#L259

I remember being very conflicted about including those when I didn't know what the impact would be.

I will look at this case some more if I have time, but hopefully I've given you enough to investigate some more if it's blocking you from accomplishing something.

from pharos.

Trass3r avatar Trass3r commented on September 16, 2024

It didn't recognize anything, just some exception and typeinfo classes.
msvc forwards new[] to the new operator (unlike gcc). So it could either call that forwarding new[] or it's inlined and calls new directly. But yes it doesn't know the VS2019 new operator hash.

Giving it the new[] address manually results in this error: Missing return value from new() call at 0x0040104F

Adding a virtual method does help it to find the ctor, dtor and virtual method. But it does not understand the usage in main of course.

from pharos.

Trass3r avatar Trass3r commented on September 16, 2024

N.B.: eh_vector_constructor could also be inlined.
https://godbolt.org/z/XsZnQc

from pharos.

sei-ccohen avatar sei-ccohen commented on September 16, 2024

Another great report. I really like they way you've used godbolt to demonstrate the issue by the way. We'll definitely want to look at this, but it's not something we're currently working on.

from pharos.

edmcman avatar edmcman commented on September 16, 2024

Just to update this, I did add a bunch of hashes for new[]. But I suspect it will still have the Missing return value from new() call at 0x0040104F problem you encountered when specifying the address manually. At some point @sei-ccohen will probably need to look into that.

from pharos.

Trass3r avatar Trass3r commented on September 16, 2024

The problem is that the number passed to new is not the size of an individual object but the sum of all objects in the array + the number of objects (which can be dynamic of course).
If this is not taken into account the tool may think it's one large object.

from pharos.

sei-eschwartz avatar sei-eschwartz commented on September 16, 2024

Yes, that is a good point. We should probably ignore the size for the [] variants because there's no easy way to know how many objects there are (right?)

from pharos.

Trass3r avatar Trass3r commented on September 16, 2024

I've checked the 2 previously posted godbolt links again.
The number of objects (size_t) is saved in front of the objects for msvc and gcc but only if virtual functions are present.

The rest of the code takes care of calling all the constructors which depends on the compiler optimizations.
Without any msvc inserts a nice function call:

eh_vector_constructor(memory, fooSize, numFoos, Foo::Foo, guard_check_icall_nop);

but with opts this loop will be inlined and potentially also the ctor if visible.

from pharos.

edmcman avatar edmcman commented on September 16, 2024

Thanks, I clearly had not looked at your examples in enough detail. At least for virtual classes we should have enough information to do something meaningful. I may work on this some over the holidays.

from pharos.

Trass3r avatar Trass3r commented on September 16, 2024

The pattern is also used for global/stack arrays, like Foo f[50]; instead of new Foo[50].

from pharos.

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.