Bug 42457

Summary: [4.5 Regression] AVR fails to build with other than C family languages
Product: gcc Reporter: Andy Hutchinson <hutchinsonandy>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: aesok, eric.weddington, gcc-bugs, mstein.lists
Priority: P3 Keywords: build
Version: 4.5.0   
Target Milestone: 4.5.0   
Host: Target: avr-*-*
Build: Known to work:
Known to fail: Last reconfirmed: 2009-12-22 03:29:41
Attachments: Make log file
PATCH to add avr-c.c

Description Andy Hutchinson 2009-12-22 03:18:10 UTC
AVR will fail to build with (default) LTO enabled.

LTO becomes enabled when a working libelf implementation is found.

Mike Stein brought this to my attention and I have been able to replicate it now I have loaded libelf.

The undefined symbol `builtin_define_std' is defined in c-cppbuiltin.c. It would appear this is not linked for some of lto compilations - yet target avr.c is.

The root cause seems to be that avr target uses `builtin_define_std' inside a staic function `avr_cpu_cpp_builtins' (avr.c) - whereas is used to be used inside a macro (avr.h). On most (all?) other targets it is used inside a macro When the macro is not used, there is no definition needed and no link error.

A relevant change on avr target was made 149519

2009-07-11  Anatoly Sokolov  <aesok@post.ru>

	* config/avr/avr.h (TARGET_CPU_CPP_BUILTINS): Redefine.
	(avr_extra_arch_macro) Remove declatation.
	* config/avr/avr.c (avr_cpu_cpp_builtins): New function.
	(avr_extra_arch_macro) Declare as static.
	* config/avr/avr-protos.h (avr_cpu_cpp_builtins): Dclare.


Using --disable-lto switch for configure allows build to complete.
Comment 1 Andy Hutchinson 2009-12-22 03:20:45 UTC
Created attachment 19366 [details]
Make log file
Comment 2 Andrew Pinski 2009-12-22 03:29:40 UTC
A way to fix this is to have avr-c.c like most other targets have.  And declare avr_cpu_cpp_builtins in there.  Note this change broke other languages besides C/C++/Objective-C/Objective-C++ so this is a regression as at one point Ada was building.
Comment 3 Andy Hutchinson 2009-12-22 21:18:18 UTC
Created attachment 19375 [details]
PATCH to add avr-c.c

Here is patch that I believe moves out the C related stuff to avr-c.

builtin_define_std and cpp_define are undeclared - since they have no prototypes - which is pretty ugly.

Compiler now builds without disabling LTO - BUT I now have LTO/WHPR problems with LD that is possibly a different bug.

I would like opinion on this before concluding the problem is fixed or indeed solution is getting closer.
Comment 4 Andy Hutchinson 2009-12-22 21:20:05 UTC
Testsuite fails all lto/whopr tests:

Example:


Executing on host: /media/verbatim/gcchead/obj-dir/gcc/xgcc -B/media/verbatim/gcchead/obj-dir/gcc/ /media/verbatim/gcchead/trunk/gcc/testsuite/gcc.c-torture/execute/builtins/abs-1.c /media/verbatim/gcchead/trunk/gcc/testsuite/gcc.c-torture/execute/builtins/abs-1-lib.c /media/verbatim/gcchead/trunk/gcc/testsuite/gcc.c-torture/execute/builtins/lib/main.c  -w  -O2 -flto  -fno-builtin-abs -DSTACK_SIZE=2048 -DNO_TRAMPOLINES  -DSIGNAL_SUPPRESS -mmcu=atmega128  /home/andy/winavrfiles/avrtest/dejagnuboards/exit.c -Wl,-u,vfprintf -lprintf_flt -Wl,-Tbss=0x802000,--defsym=__heap_end=0x80ffff  -lm   -o /media/verbatim/gcchead/obj-dir/gcc/testsuite/gcc/abs-1.x6    (timeout = 300)
spawn /media/verbatim/gcchead/obj-dir/gcc/xgcc -B/media/verbatim/gcchead/obj-dir/gcc/ /media/verbatim/gcchead/trunk/gcc/testsuite/gcc.c-torture/execute/builtins/abs-1.c /media/verbatim/gcchead/trunk/gcc/testsuite/gcc.c-torture/execute/builtins/abs-1-lib.c /media/verbatim/gcchead/trunk/gcc/testsuite/gcc.c-torture/execute/builtins/lib/main.c -w -O2 -flto -fno-builtin-abs -DSTACK_SIZE=2048 -DNO_TRAMPOLINES -DSIGNAL_SUPPRESS -mmcu=atmega128 /home/andy/winavrfiles/avrtest/dejagnuboards/exit.c -Wl,-u,vfprintf -lprintf_flt -Wl,-Tbss=0x802000,--defsym=__heap_end=0x80ffff -lm -o /media/verbatim/gcchead/obj-dir/gcc/testsuite/gcc/abs-1.x6
/home/andy/local/avr/lib/gcc/avr/4.5.0/../../../../avr/bin/ld: -f may not be used without -shared
compiler exited with status 1
output is:
/home/andy/local/avr/lib/gcc/avr/4.5.0/../../../../avr/bin/ld: -f may not be used without -shared

FAIL: gcc.c-torture/execute/builtins/abs-1.c compilation,  -O2 -flto 
Comment 5 Andy Hutchinson 2009-12-24 20:32:49 UTC
Subject: Bug 42457

Author: hutchinsonandy
Date: Thu Dec 24 20:32:38 2009
New Revision: 155460

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155460
Log:
2009-12-24  Andy Hutchinson  <hutchinsonandy@gcc.gnu.org>

	PR target/42457
	* config/avr/avr.c (avr_extra_arch_macro): Remove static.
	(avr_cpu_cpp_builtins): Remove.
	* config/avr/avr.h (avr_extra_arch_macro): Add prototype.
	* config/avr/avr-c.c: New File.
	(avr_cpu_cpp_builtins) : Add.
	* config/avr/t-avr: Add make information for avr-c.
	* config.gcc (avr-*-*): Include avr-c.o as c and cpp object. 

Added:
    trunk/gcc/config/avr/avr-c.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config.gcc
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.h
    trunk/gcc/config/avr/t-avr

Comment 6 Andy Hutchinson 2009-12-24 20:33:45 UTC
Fixed 4.5