Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

nano.specs not using the nano version of the C++ libraries #45

Open
ilg-ul opened this issue May 2, 2022 · 7 comments
Open

nano.specs not using the nano version of the C++ libraries #45

ilg-ul opened this issue May 2, 2022 · 7 comments

Comments

@ilg-ul
Copy link

ilg-ul commented May 2, 2022

I've just built a new version of the RISC-V bare-metal toolchain, using GCC 11.3 and the latest newlib, including the newlinb-nano libraries, and I noticed that the nano.spec does not replace the -lstdc++ and -lsupc++ with their size optimised nano versions, as the Arm bare-metal toolchains do.

For example, the arm-none-eabi toolchains uses:

*link:
%(nano_link) %:replace-outfile(-lc -lc_nano) %:replace-outfile(-lg -lg_nano) %:replace-outfile(-lrdimon -lrdimon_nano) %:replace-outfile(-lstdc++ -lstdc++_nano) %:replace-outfile(-lsupc++ -lsupc++_nano)

while the riscv-none-embed toolchain uses:

*link:
%(nano_link) %:replace-outfile(-lc -lc_nano) %:replace-outfile(-lg -lg_nano) %:replace-outfile(-lm -lm_nano)

Could we add the same substitutions to the RISC-V newlib in order to make applications using newlib-nano benefit from the size optimised versions of the C++ libraries?

If so, what is the procedure to get such a patch accepted upstream?

@ilg-ul
Copy link
Author

ilg-ul commented May 14, 2022

If this repo is deprecated, can you suggest the right one?

@jim-wilson
Copy link
Collaborator

This repo isn't dead, but there has always been a shortage of people helping to maintain it, which is probably worse now that I'm "retired". Also, I've had an out of town visitor for the last 2 weeks, and was in Las Vegas before that, so I'm about a month behind in handling stuff.

We currently build newlib twice, once regular, and once nano, then rename files from the nano build to have a nano extension, so we have both regular and nano versions of newlib that we can use when linking. However, we only build libstdc++ and libsupc++ once. We would need Makefile changes to build a second version of these libraries. Since the gcc makefile doesn't support building them twice, we probably need to build the stage2 gcc twice, and then rename files from the second build. That would be a project, not just a simple bug fix. Then we need to fix the libgloss nano.spec file upstream, and backport into riscv-gnu-toolchain.

Not clear how useful that would be, since nano is for reducing code size, and there is no code size reduced version of libstdc++ unless someone does major work on it, which is an even bigger project. If ARM has already done some work in this area, then someone needs to reverse engineer what they did so that we can do the same thing for RISC-V.

None of this is likely to happen unless someone volunteers to do the work.

@ilg-ul
Copy link
Author

ilg-ul commented May 15, 2022

there is no code size reduced version of libstdc++ unless someone does major work on it

No need for any major work, just compile the nano version of stage2 with -Os, and the regular one with -O3.

If ARM has already done some work in this area ...

The Arm embedded toolchains had this feature from the very beginning, and my RISC-V toolchains always built the stage2 twice, to discover now that the nano variant is ignored, because the specs file does not consider it. :-(

Assuming the specs file is patched upstream, the rest is peanuts.

@ilg-ul
Copy link
Author

ilg-ul commented May 15, 2022

I think that for my binary distribution the simplest workaround is to patch that specs file after archive download.

If you'll ever update the upstream file, the patch will become ineffective.

@ilg-ul
Copy link
Author

ilg-ul commented May 18, 2022

I applied a run-time patch and temporarily fixed the problem:

However I still suggest to fix the upstream configuration, and bring it in line with the Arm configuration.

@kito-cheng
Copy link
Collaborator

IIUC, that also require build script modification to building -lstdc++_nano and -lsupc++_nano rather than just adding that to spec file?

@ilg-ul
Copy link
Author

ilg-ul commented May 18, 2022

I don't know about your build scripts, but for the xPack RISC-V toolchain I use exactly the same scripts as for the Arm toolchain, and the nano versions of the C++ libraries are built anyway.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants