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

-nostartfiles is not an LDFLAG #127

Closed
celledge opened this issue Jun 3, 2021 · 14 comments
Closed

-nostartfiles is not an LDFLAG #127

celledge opened this issue Jun 3, 2021 · 14 comments
Assignees

Comments

@celledge
Copy link

celledge commented Jun 3, 2021

Newer version of GCC (10.2.0 tested) have added extra error checking to the LD linker. If you now pass a flag that it doesn't recognize it will suggest an alternative. Additionally -nostartfiles is a GCC flag, not a LD flag. Together this causes the at91bootstrap make file to generate a linking error:

arm-poky-linux-gnueabi-ld: Error: unable to disambiguate: -nostartfiles (did you mean --nostartfiles ?)

Explanation available here:
https://sourceware.org/pipermail/binutils/2021-June/116826.html

I think -nostartfiles was just silently ignored previously.

@ehristev
Copy link
Contributor

ehristev commented Jun 7, 2021

Hi,

I am using this GCC version
gcc version 10.2.1 20201103 (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16))

I do not see this warning. How did you hit this problem ?
Anything special you did ?
I see you are using the yocto/poky toolchain in fact.

@ehristev ehristev self-assigned this Jun 7, 2021
@ehristev
Copy link
Contributor

ehristev commented Jun 7, 2021

According to GCC documentation I see this parameter is available for the linker
https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

@celledge
Copy link
Author

celledge commented Jun 7, 2021

I'm sorry, this is actually caused by binutils version 2.36. The 10.2.1 GCC ARM toolchain you are using shipped with binutils version 2.35.1. arm-none-linux-gnueabihf-ld is just an alias for the binutils ld executable.

They have identical sha256 hashes:
788345c3d11cffae5f50f1e74d87575afbeaa8b2824cfe518d7e5f4cb23b55f7 arm-none-linux-gnueabihf-ld
788345c3d11cffae5f50f1e74d87575afbeaa8b2824cfe518d7e5f4cb23b55f7 ../arm-none-linux-gnueabihf/bin/ld

What -nostartfiles is actually doing is:
-n => Do not page align data, but this flag is already specified elsewhere on the LDFLAGS, so not a problem
-ostartfiles => Output to file named "startfiles", but this is being overridden by the later -o flag

I tried to remove the -nostartfiles from the makefile to see if it changed anything in the map file when compiling with the 10.2.1 GCC ARM Toolchain, but I discovered that if I touch the Makefile at all (even just adding a comment) that the output map file changed on me. Not sure what's causing that yet, but it makes it hard to compare the differences with and without the flag. If I use a Makefile with an extra comment line, there doesn't appear to be a difference in the map files generated with and without the -nostartfiles.

@celledge
Copy link
Author

celledge commented Jun 7, 2021

Oh. The difference in the map files was being generated by the addition of a '-dirty' statement to the DAT91BOOTSTRAP_VERSION. Once it was made to always be dirty, there was no apparent difference with and without the -nostartfiles when using GCC 10.2.1 / Binutils 2.35.1.

If using Binutils 2.36.1 with their improved flag parsing, the link will fail due to -nostartfiles being an invalid flag.

@ehristev
Copy link
Contributor

ehristev commented Jun 8, 2021

I believe the purpose of the -nostartfiles is to stop the toolchain from actually using start files .
Maybe the correct place to put this flag is in CC flags and not the LDFLAGS ?
Have you tried to place it there and see what happens?

Thanks for shedding some light on this.

@celledge
Copy link
Author

celledge commented Jun 8, 2021

I don't think -nostartfiles is needed at all. It's intended to be used when using gcc as the final linker:
gcc -nostartfiles -o foo.elf foo.o bar.o
That would generate a binary with the start files excluded.

Instead this project is calling the binutils linker and telling it exactly what objects to include:
ld -n -o foo.elf foo.o bar.o
I suspect this decision was made to make it easy to pass in the assembler start sequence from crt0_gnu.S. It's possible the original project used gcc as the linker early in development until it was decided to swap to binutils which left the flag as vestigial but not throwing any error.

@ehristev
Copy link
Contributor

ehristev commented Jun 8, 2021

@nirvann Hi, what's your take on this one ? As you have tested bootstrap on various platforms and toolchains.
Thanks !

@nirvann
Copy link
Contributor

nirvann commented Jun 8, 2021

Hi, I didn't met the linker error message either.
But I agree with Nick Clifton's answer on binutils ML.

This -nostartfiles argument has been erroneously given to ld since at least Year 2010 in commit 6ea5bf7. There are traces that -Wl, was used prior to that, showing that the linker was called indirectly in the past.
Now -nostartfiles simply has to be removed from LDFLAGS.
As pointed out by @celledge in our ld command line there are explicit -n -o $(BINDIR)/$(BOOT_NAME).elf options, hence removing -nostartfiles will not alter the build.

@ehristev
Copy link
Contributor

ehristev commented Jun 8, 2021

@celledge Do you wish to make a patch for this, or you wish me to do it ?
You would either be the author (first case) or the suggester (Suggested-by) (second case)

Thanks !

celledge pushed a commit to digitallumens/at91bootstrap that referenced this issue Jun 8, 2021
Binutils linker ld does not support the flag -nostartfiles. This is interpreted as "-n -o startfiles" which fortunately has no impact on the build process. Removing -nostartfiles has no impact on the build.

Binutils 2.36 and later ld has improved flag parsing and throws an error if -nostartfiles is passed as an argument. Removing the flag fixes the problem.
Details on the Binutils ML: https://sourceware.org/pipermail/binutils/2021-June/116826.html

resolves linux4sam#127
@celledge
Copy link
Author

@ehristev Is this pull request sufficient or do you need anything else?

@ehristev
Copy link
Contributor

Yes it's fine. I will apply this soon.

@ehristev
Copy link
Contributor

Fixed by applying patch. Thanks again !

@tpetazzoni
Copy link

Could you make a new release of at91bootstrap 3.x with this fix? Thanks!

buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue Aug 7, 2021
AT91Bootstrap 3.10.2 has a bug in its Makefile:[1] it gives the
-nostartfiles flag to the ld command, although this is a gcc flag, not
an ld flag. The bug happens to be harmless when using binutils 2.35.
However, the ld shipped with binutils 2.36 is more strict in its option
parsing, and fails with the following error:

    .../output/host/bin/arm-buildroot-linux-uclibcgnueabihf-ld:
    Error: unable to disambiguate: -nostartfiles
    (did you mean --nostartfiles ?)

The bug was fixed upstream in commit 3207586a.[2] However, since there
has been no tagged 3.x release since then, we just upgrade to the
current head of the branch at91bootstrap-3.x.

Fixes:

  https://gitlab.com/buildroot.org/buildroot/-/jobs/1478738145
  https://gitlab.com/buildroot.org/buildroot/-/jobs/1478738152

[1] linux4sam/at91bootstrap#127
[2] linux4sam/at91bootstrap@3207586

Signed-off-by: Edgar Bonet <bonet@grenoble.cnrs.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
@ehristev
Copy link
Contributor

3.10.3 tagged and pushed.
Thanks for the heads up.
(I was out of office)

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

Successfully merging a pull request may close this issue.

4 participants