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

Link Time Optimisation 6.2.0 #46

Closed
tuna-f1sh opened this issue Apr 25, 2017 · 9 comments
Closed

Link Time Optimisation 6.2.0 #46

tuna-f1sh opened this issue Apr 25, 2017 · 9 comments

Comments

@tuna-f1sh
Copy link

I use homebrew-avr with Arduino-mk and have been for a while. Updating to the latest formula, I suffered a segmentation fault at the linking stage.

Doing some digging, this is due to the -flto flag, set by default for Arduino-mk (and presumably arduino builds) but missing from the 6.2.0 homebrew build. I'm not that well versed with the gcc compiler but Link Time Optimization (lto) seems to be merged into the latest branch and was working in the previous homebrew formulae - is there a reason it's missing from the homebrew build?

One can workaround it be manually setting the C++ flags - excluding -flto - but it would be nice to have it working by default.

Thanks.

@larsimmisch
Copy link
Contributor

@tuna-f1sh: can you show a minimal example of the compile/link rules in your Makefile? In particular, do you use ld for linking or gcc?

Note to self: I'm not sure what causes this, because -enable-lto is the default according to https://gcc.gnu.org/install/configure.html. But there are some mentions that LTO is a linker plugin, so we may have to make sure the gcc lto plugin is picked up by binutils.

@ladislas
Copy link
Member

I have the same issue. Did not notice it before as i was overriding the flags.

@larsimmisch
Copy link
Contributor

larsimmisch commented Apr 25, 2017

@tuna-f1sh Just looked at Arduino-mk: disregard my question. $(CC) is invoked as the linker

@tuna-f1sh
Copy link
Author

tuna-f1sh commented Apr 25, 2017

Appears to be a bug in the compiler. The Arch package had the same problem. There is a work around but seems to be fixed in the latest avr-libc? An issue in the Arduino repository too.

@ladislas
Copy link
Member

that's super interesting! :)

maybe using avr-gcc 6.3.0 and Binutils 2.26.1 will fix the issue?

https://gcc.gnu.org/gcc-6/changes.html

@larsimmisch
Copy link
Contributor

The underlying issue seems to be this (arduino/Arduino#660 (comment)):

Small update: lto build on 6.1 segfaults on libraries using virtual inheritance. Hence, adding -fno-devirtualize to c and cpp extra flags solves the segfault.

I would argue that this is a gcc bug - whatever it does, it should not segfault. Can you try compiling with -fno-devirtualize and -flto?

In any case, this should probably be reported to gcc and it looks as if the best we can do right now is to suggest workarounds - and removing -flto does work for you.

Have you got time to prepare a minimal reproduction case?

@larsimmisch
Copy link
Contributor

@ladislas yes, good idea. But we need a reproducible test case

@ladislas
Copy link
Member

Just tried and it doesn't work...

here is my test case: https://github.com/ladislas/Bare-Arduino-Project/tree/lto-bug

on branch lto-bug in ./src/BarProject just run make on OSX.

@ladislas
Copy link
Member

ladislas commented Aug 4, 2017

@tuna-f1sh this is being discussed here: sudar/Arduino-Makefile#486

updating arduino-mk should fix the issue.

@ladislas ladislas closed this as completed Aug 4, 2017
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

3 participants