public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "matthijs at stdin dot nl" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/56533] New: Linker problem on avr with lto and main function inside archive Date: Tue, 05 Mar 2013 12:33:00 -0000 [thread overview] Message-ID: <bug-56533-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56533 Bug #: 56533 Summary: Linker problem on avr with lto and main function inside archive Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned@gcc.gnu.org ReportedBy: matthijs@stdin.nl When trying to add lto to my Arduino program, it stopped compiling complaining about missing symbols. I've managed to reduce the problem to below minimal example. Note that removing anything from below example makes the problem disappear. In particular, the problem disappears when: * any of the linker options is removed: -mmcu=atmega328p -Os -flto -fwhole-program * the -flto compiler option is removed * using normal gcc (amd64) instead of avr-gcc * linking main.o instead of main.a * declaring realmain as externally_visible in realmain.c Note that in this example, the actual main() function is inside an archive, which is probably the reason for this bug / problem. $ avr-gcc --version avr-gcc (GCC) 4.7.2 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ avr-ld --version GNU ld (GNU Binutils) 2.20.1.20100303 Copyright 2009 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. $ cat main.c int realmain(void); int main(void) { return realmain(); } $ cat realmain.c int realmain(void) { } $ cat do #!/bin/sh set -x rm -f main.a /usr/bin/avr-gcc -c main.c -o main.o /usr/bin/avr-ar rcs main.a main.o /usr/bin/avr-gcc -c -flto realmain.c -o realmain.o /usr/bin/avr-gcc -mmcu=atmega328p -Os -flto -fwhole-program realmain.o main.a $ ./do + rm -f main.a + /usr/bin/avr-gcc -c main.c -o main.o + /usr/bin/avr-ar rcs main.a main.o + /usr/bin/avr-gcc -c -flto realmain.c -o realmain.o + /usr/bin/avr-gcc -mmcu=atmega328p -Os -flto -fwhole-program realmain.o main.a main.a(main.o): In function `main': main.c:(.text+0x8): undefined reference to `realmain' collect2: error: ld returned 1 exit status
next reply other threads:[~2013-03-05 12:33 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-03-05 12:33 matthijs at stdin dot nl [this message] 2013-03-05 12:39 ` [Bug target/56533] " rguenth at gcc dot gnu.org 2013-03-05 12:56 ` matthijs at stdin dot nl 2013-03-05 13:06 ` matthijs at stdin dot nl 2013-03-05 13:41 ` rguenth at gcc dot gnu.org 2013-03-05 14:38 ` matthijs at stdin dot nl 2013-03-05 14:40 ` matthijs at stdin dot nl
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-56533-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).