Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMB2.0: Automatic stdlib size overhead adjustment #191

Open
I-mikan-I opened this issue Mar 4, 2024 · 6 comments
Open

EMB2.0: Automatic stdlib size overhead adjustment #191

I-mikan-I opened this issue Mar 4, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@I-mikan-I
Copy link
Contributor

We try to subtract the size overhead for libraries, startup files, crt when calculating the size of benchmarks.
Currently this is done as follows:

  • Each benchmark is linked against "dummy" libraries that are empty
  • The size of the executable elf is calculated by summing up certain sections

Issues with the current approach

  • Crt/startup files may still be linked to the final executable
  • requires a user to specify dummy files for any user libraries

New approach (planned for embench-iot 2.0)

  • Compile a "dummy benchmark", which is empty and gets linked with support files/libraries
  • Compute the size of said dummy and subtract it from each benchmark when computing the size.
@I-mikan-I I-mikan-I added the enhancement New feature or request label Mar 4, 2024
@I-mikan-I I-mikan-I self-assigned this Mar 4, 2024
@I-mikan-I
Copy link
Contributor Author

addressed in ace099e

@I-mikan-I
Copy link
Contributor Author

There are some issues i see with the new approach:

  • The linker may eliminate unused library symbols because they aren't used by the dummy benchmark, but would be used in the actual benchmarks
    • this results in negative sizes for some sections
    • one fix that i used in the commit is to compile with -rdynamic/-Wl,--export-dynamic, which exports all symbols
  • This cannot account for separate libraries used in each benchmark, such as -lm

Perhaps it would be a better idea to compile each benchmark as a shared library with -nostartupfiles -nostdlib -c?

@I-mikan-I I-mikan-I changed the title Automatic stdlib size overhead adjustment EMB2.0: Automatic stdlib size overhead adjustment Mar 4, 2024
@PaoloS02 PaoloS02 added this to the Embench 2.0 milestone Mar 4, 2024
@jeremybennett
Copy link
Collaborator

I'm not sure that shared libraries help if you are going to compile down for a small embedded device.

One option is to use attributes to force particular functions and symbols to be retained. Would adding __attribute__ ((noinline)) __attribute__ ((externally_visible)) to the declaration of the relevant functions do the trick?

@I-mikan-I
Copy link
Contributor Author

I'm not sure that shared libraries help if you are going to compile down for a small embedded device.

It wouldn't be possible to run them as dylibs, i just thought if you compile them as such, you remove any libraries and startup files from the elf/macho and can get an accurate size measurement for the code size.
If we want to run the same file that we measured the size of then this isn't viable.

One option is to use attributes to force particular functions and symbols to be retained. Would adding __attribute__ ((noinline)) __attribute__ ((externally_visible)) to the declaration of the relevant functions do the trick?

Thanks, I'll try this attribute. This should improve --export-dynamic by also preventing inlining.

@I-mikan-I
Copy link
Contributor Author

I compared the results of either using __attribute__ ((noinline)) __attribute__ ((externally_visible)), or using -Wl,--export-all.

The --export-all variant seems to be more accurate: for tarfind it reports a size of 265 bytes, the actual size of the benchmark_body code being 260 bytes.

@simonpcook
Copy link
Contributor

simonpcook commented Mar 6, 2024

I thought it was previously discussed that embench was moving away from library subtraction in part because of issues like the ones you’ve raised, did this now change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants