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

Why does freedom-metal have any 'exit' handling? #240

Open
keith-packard opened this issue Apr 2, 2020 · 7 comments
Open

Why does freedom-metal have any 'exit' handling? #240

keith-packard opened this issue Apr 2, 2020 · 7 comments
Assignees

Comments

@keith-packard
Copy link
Contributor

Given that there's no well-defined behavior for 'exit' in an embedded environment, it seems odd that crt0.S includes calls to atexit and exit. I'd suggest removing all of that and having crt0.S cause a trap if main ever returns.

Changing this would allow an embedded RTOS using freedom metal to define it's own _exit function, and we'd be able to build newlib-nano with per-thread atexit handling if desired.

@bsousi5
Copy link
Collaborator

bsousi5 commented Apr 2, 2020 via email

@nategraff-sifive
Copy link
Contributor

Nowhere do we even use destructors in freedom metal. I added them just because "well, we have constructors". I think it's reasonable to remove them if they're just bloating everyone's applications to no benefit.

@nategraff-sifive
Copy link
Contributor

As far as the exit goes, the return value from main does get sent to the shutdown handler so that test status can be reported in QEMU and RTL simulation.

@keith-packard
Copy link
Contributor Author

Exit was done for RTL test run

Any idea what that's supposed to do? crt0.S will just branch to whatever ra is pointing at, which
is not likely to be helpful.

@keith-packard
Copy link
Contributor Author

As far as the exit goes, the return value from main does get sent to the shutdown handler so that test status can be reported in QEMU and RTL simulation.

Right, and semihosting also has exit support, which I've been using for testing picolibc under QEMU.

So, I think my concern is more about what crt0.S does than whether anything using freedom-metal should be able to call exit sensibly. I'd like to remove the atexit and exit calls from that code, and have it trap if main returns instead. This would avoid pulling in unnecessary libc code when building 'normal' embedded applications.

Ideally, we'd find a way to make QEMU and the RTL simulator generate an error so that tests which return from main fail instead of hang forever.

@bsousi5
Copy link
Collaborator

bsousi5 commented Apr 2, 2020 via email

@keith-packard
Copy link
Contributor Author

You may already aware of this. But we would not want to make the change or merge this change for the next couple of week.

There's no hurry, just another architecture change that we might consider. It's "harmless" as the code should never get executed, it just wastes memory.

bsousi5 added a commit that referenced this issue Apr 8, 2020
Updating BSP to pickup FDT inline support for generates metal files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants