Bug 13612

Summary: segmentation fault with --relax option, avr target
Product: binutils Reporter: Fabio Varesano <fabio.varesano>
Component: ldAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gjl
Priority: P2    
Version: 2.22   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: Test case
.i .s .o

Description Fabio Varesano 2012-01-22 09:37:52 UTC
Hello, it seems that ld has some issue when run with --relax on AVR targets resulting in a segmentation fault.

See details at http://comments.gmane.org/gmane.comp.gnu.binutils/55903

Simple test case:
//avr-gcc main.c -mrelax -ffunction-sections -mmcu=atmega128
// using binutils-2.22
void func2(int a)
{
}

void func1(void)
{
  func2(10);
}

int main(void)
{
  func1();
}
Comment 1 Fabio Varesano 2012-01-22 13:45:19 UTC
More details:

[fabio@gamma ldbug]$ avr-gcc main.c -mrelax -ffunction-sections -mmcu=atmega128 -save-temps -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.6.2/lto-wrapper
Target: avr
Configured with: ../configure --disable-libssp --disable-nls --enable-languages=c,c++ --infodir=/usr/share/info --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --prefix=/usr --target=avr --with-gnu-as --with-gnu-ld --with-as=/usr/bin/avr-as --with-ld=/usr/bin/avr-ld
Thread model: single
gcc version 4.6.2 (GCC) 
COLLECT_GCC_OPTIONS='-mrelax' '-ffunction-sections' '-mmcu=atmega128' '-save-temps' '-v'
 /usr/lib/gcc/avr/4.6.2/cc1 -E -quiet -v -imultilib avr51 main.c -mrelax -mmcu=atmega128 -ffunction-sections -fpch-preprocess -o main.i
ignoring nonexistent directory "/usr/lib/gcc/avr/4.6.2/../../../../avr/sys-include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/avr/4.6.2/include
 /usr/lib/gcc/avr/4.6.2/include-fixed
 /usr/lib/gcc/avr/4.6.2/../../../../avr/include
End of search list.
COLLECT_GCC_OPTIONS='-mrelax' '-ffunction-sections' '-mmcu=atmega128' '-save-temps' '-v'
 /usr/lib/gcc/avr/4.6.2/cc1 -fpreprocessed main.i -quiet -dumpbase main.c -mrelax -mmcu=atmega128 -auxbase main -version -ffunction-sections -o main.s
GNU C (GCC) version 4.6.2 (avr)
        compiled by GNU C version 4.6.2 20111223 (prerelease), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (GCC) version 4.6.2 (avr)
        compiled by GNU C version 4.6.2 20111223 (prerelease), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7f65a69733ae527e3ce90dec3bf8f000
COLLECT_GCC_OPTIONS='-mrelax' '-ffunction-sections' '-mmcu=atmega128' '-save-temps' '-v'
 /usr/bin/avr-as -v -mmcu=atmega128 -o main.o main.s
GNU assembler version 2.22.51 (avr) using BFD version (GNU Binutils) 2.22.51.20120117
COMPILER_PATH=/usr/lib/gcc/avr/4.6.2/:/usr/lib/gcc/avr/4.6.2/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.6.2/:/usr/lib/gcc/avr/
LIBRARY_PATH=/usr/lib/gcc/avr/4.6.2/avr51/:/usr/lib/gcc/avr/4.6.2/../../../../avr/lib/avr51/:/usr/lib/gcc/avr/4.6.2/:/usr/lib/gcc/avr/4.6.2/../../../../avr/lib/
COLLECT_GCC_OPTIONS='-mrelax' '-ffunction-sections' '-mmcu=atmega128' '-save-temps' '-v'
 /usr/lib/gcc/avr/4.6.2/collect2 --relax -m avr51 -Tdata 0x800100 /usr/lib/gcc/avr/4.6.2/../../../../avr/lib/avr51/crtm128.o -L/usr/lib/gcc/avr/4.6.2/avr51 -L/usr/lib/gcc/avr/4.6.2/../../../../avr/lib/avr51 -L/usr/lib/gcc/avr/4.6.2 -L/usr/lib/gcc/avr/4.6.2/../../../../avr/lib main.o -lgcc -lc -lgcc
Comment 2 Fabio Varesano 2012-01-22 13:46:11 UTC
Created attachment 6170 [details]
Test case
Comment 3 Fabio Varesano 2012-01-22 13:48:09 UTC
Created attachment 6171 [details]
.i .s .o
Comment 4 Fabio Varesano 2012-01-22 13:51:40 UTC
Upgraded to current binutils weekly snapshot. I'm no more able to replicate the issue.
Comment 5 Georg-Johann Lay 2012-01-22 14:31:25 UTC

*** This bug has been marked as a duplicate of bug 12161 ***