Bug 43556 - Ubuntu : segmentation fault in strchr() obtained with gcc4.4.3 and not with gcc4.4.1
Summary: Ubuntu : segmentation fault in strchr() obtained with gcc4.4.3 and not with g...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-28 17:09 UTC by Eric CABRET
Modified: 2010-03-29 21:48 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Preprocessed source not OK with "gcc -E main.c" (3.80 KB, text/plain)
2010-03-28 20:34 UTC, Eric CABRET
Details
Preprocessed source OK with "gcc -E main.c" (3.80 KB, text/plain)
2010-03-28 20:34 UTC, Eric CABRET
Details
a.out OK obtained by command "gcc main.c" (2.85 KB, application/octet-stream)
2010-03-28 20:35 UTC, Eric CABRET
Details
a.out not OK obtained by command "gcc main.c" (2.41 KB, application/octet-stream)
2010-03-28 20:36 UTC, Eric CABRET
Details
a.out OK obtained by command "gcc -g main.c" (with debug infos on 64bit ubuntu) (3.07 KB, application/octet-stream)
2010-03-28 20:45 UTC, Eric CABRET
Details
a.out not OK obtained by command "gcc -g main.c" (with debug infos on 64bit ubuntu) (2.87 KB, application/octet-stream)
2010-03-28 20:45 UTC, Eric CABRET
Details
File obtained with command "strace -s 1024 ./a_ok_withdebug.out > strace_s1024_a_ok.txt 2>&1" (1.06 KB, text/plain)
2010-03-28 20:52 UTC, Eric CABRET
Details
File obtained with command "strace -s 1024 ./a_nok_withdebug.out > strace_s1024_a_nok.txt 2>&1" (1.06 KB, text/plain)
2010-03-28 20:52 UTC, Eric CABRET
Details
File obtained with command "strace -s 1024 ./a_nok_withdebug.out > strace_s1024_a_nok.txt 2>&1" (executed on the SAME SYSTEM than file attachment #20240 that was OK) (1.17 KB, text/plain)
2010-03-28 21:01 UTC, Eric CABRET
Details
main.c with segmentation fault if compiled with gcc-4.4.3 (211 bytes, text/plain)
2010-03-29 08:50 UTC, Eric CABRET
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric CABRET 2010-03-28 17:09:14 UTC
My system is Ubuntu 64 bits Lucid Lynx.
with this following small program, I obtain a crazy segmentation fault in strchr() with gcc4.4.3-4ubuntu5 AND NOT with gcc4.4.1-4ubuntu9 (with same glibc in both case) :

// gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 -> execution gives a "segmentation fault"
// gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1 -> execution is fully OK
#include <stdio.h>
#include <string.h>

char t[]="It: is a gcc4.4.3 bug";

main() {
char *p;

puts(t);
p = strchr(t, ':');
printf("p='%s'\n", p);

return 0;
}

Many best regards.
Eric.
Comment 1 Richard Biener 2010-03-28 17:20:04 UTC
Works for me (thus I suggest to file a bug with Ubuntu).

Which optimization options?  Please attach preprocessed source.
Comment 2 Eric CABRET 2010-03-28 20:34:28 UTC
Created attachment 20234 [details]
Preprocessed source not OK with "gcc -E main.c"
Comment 3 Eric CABRET 2010-03-28 20:34:49 UTC
Created attachment 20235 [details]
Preprocessed source OK with "gcc -E main.c"
Comment 4 Eric CABRET 2010-03-28 20:35:49 UTC
Created attachment 20236 [details]
a.out OK obtained by command "gcc main.c"
Comment 5 Eric CABRET 2010-03-28 20:36:15 UTC
Created attachment 20237 [details]
a.out not OK obtained by command "gcc main.c"
Comment 6 Eric CABRET 2010-03-28 20:37:42 UTC
Here are new files (preprocessed sources OK and not OK) and binaries obtained only with command "gcc main.c"
Comment 7 Eric CABRET 2010-03-28 20:45:18 UTC
Created attachment 20238 [details]
a.out OK obtained by command "gcc -g main.c" (with debug infos on 64bit ubuntu)
Comment 8 Eric CABRET 2010-03-28 20:45:44 UTC
Created attachment 20239 [details]
a.out not OK obtained by command "gcc -g main.c" (with debug infos on 64bit ubuntu)
Comment 9 Eric CABRET 2010-03-28 20:52:14 UTC
Created attachment 20240 [details]
File obtained with command "strace -s 1024 ./a_ok_withdebug.out > strace_s1024_a_ok.txt 2>&1"
Comment 10 Eric CABRET 2010-03-28 20:52:36 UTC
Created attachment 20241 [details]
File obtained with command "strace -s 1024 ./a_nok_withdebug.out > strace_s1024_a_nok.txt 2>&1"
Comment 11 Eric CABRET 2010-03-28 21:01:51 UTC
Created attachment 20242 [details]
File obtained with command "strace -s 1024 ./a_nok_withdebug.out > strace_s1024_a_nok.txt 2>&1" (executed on the SAME SYSTEM than file attachment #20240 [details] that was OK)
Comment 12 Pawel Sikora 2010-03-29 07:56:08 UTC
i can confirm that gpf on my system (gcc-4.4.4, glibc-2.11.1).
i see diffs in relocations.

$ readelf -sW a_ok*|grep strchr
 5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strchr@GLIBC_2.2.5 (2)
70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strchr@@GLIBC_2.2.5

$ readelf -sW a_nok*|grep strchr
 5: 0000000000601050    41 IFUNC   GLOBAL DEFAULT   26 strchr@GLIBC_2.2.5 (2)
69: 0000000000601050    41 IFUNC   GLOBAL DEFAULT   26 strchr@@GLIBC_2.2.5
Comment 13 Eric CABRET 2010-03-29 08:08:39 UTC
Dear Pawel,
Please could you tell me exactly if you had gpf on your system by recompiling and then executing my main.c ?
Many thanks for your contribution.
Eric.

(In reply to comment #12)
> i can confirm that gpf on my system (gcc-4.4.4, glibc-2.11.1).
> i see diffs in relocations.
> 
> $ readelf -sW a_ok*|grep strchr
>  5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strchr@GLIBC_2.2.5 (2)
> 70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strchr@@GLIBC_2.2.5
> 
> $ readelf -sW a_nok*|grep strchr
>  5: 0000000000601050    41 IFUNC   GLOBAL DEFAULT   26 strchr@GLIBC_2.2.5 (2)
> 69: 0000000000601050    41 IFUNC   GLOBAL DEFAULT   26 strchr@@GLIBC_2.2.5
> 
Comment 14 Pawel Sikora 2010-03-29 08:23:13 UTC
(In reply to comment #13)
> Dear Pawel,
> Please could you tell me exactly if you had gpf on your system by recompiling
> and then executing my main.c ?

i've only ran attached binaries (a_{n}ok_withdebug.out) under gdb.
Comment 15 Eric CABRET 2010-03-29 08:46:59 UTC
What's happened if you recompile and run main.c with your gcc4.4.4 ?

(In reply to comment #14)
> (In reply to comment #13)
> > Dear Pawel,
> > Please could you tell me exactly if you had gpf on your system by recompiling
> > and then executing my main.c ?
> 
> i've only ran attached binaries (a_{n}ok_withdebug.out) under gdb.
> 

Comment 16 Eric CABRET 2010-03-29 08:50:14 UTC
Created attachment 20246 [details]
main.c with segmentation fault if compiled with gcc-4.4.3
Comment 17 Pawel Sikora 2010-03-29 09:05:19 UTC
(In reply to comment #15)
> What's happened if you recompile and run main.c with your gcc4.4.4 ?

works fine because my toolchain doesn't emit STT_GNU_IFUNC
mark for strchr() symbol. you should ask Ubuntu support about
this issue.
Comment 18 Eric CABRET 2010-03-29 09:11:50 UTC
Thanks Pawel.

(In reply to comment #17)
> (In reply to comment #15)
> > What's happened if you recompile and run main.c with your gcc4.4.4 ?
> 
> works fine because my toolchain doesn't emit STT_GNU_IFUNC
> mark for strchr() symbol. you should ask Ubuntu support about
> this issue.
> 

Comment 19 Richard Biener 2010-03-29 09:45:30 UTC
Maybe HJL has an idea, too.
Comment 20 H.J. Lu 2010-03-29 13:55:37 UTC
(In reply to comment #12)
> i can confirm that gpf on my system (gcc-4.4.4, glibc-2.11.1).
> i see diffs in relocations.
> 
> $ readelf -sW a_ok*|grep strchr
>  5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strchr@GLIBC_2.2.5 (2)
> 70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strchr@@GLIBC_2.2.5
> 
> $ readelf -sW a_nok*|grep strchr
>  5: 0000000000601050    41 IFUNC   GLOBAL DEFAULT   26 strchr@GLIBC_2.2.5 (2)
> 69: 0000000000601050    41 IFUNC   GLOBAL DEFAULT   26 strchr@@GLIBC_2.2.5
> 

This is a linker bug. Please report it to Ubuntu. Undefined
functions should never be marked as IFUNC.
Comment 21 Eric CABRET 2010-03-29 14:59:34 UTC
OK, I'm going to transfer this problem to Ubuntu.
The linker is GNU ld in package binutils, isn't it ?


(In reply to comment #20)
> (In reply to comment #12)
> > i can confirm that gpf on my system (gcc-4.4.4, glibc-2.11.1).
> > i see diffs in relocations.
> > 
> > $ readelf -sW a_ok*|grep strchr
> >  5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strchr@GLIBC_2.2.5 (2)
> > 70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strchr@@GLIBC_2.2.5
> > 
> > $ readelf -sW a_nok*|grep strchr
> >  5: 0000000000601050    41 IFUNC   GLOBAL DEFAULT   26 strchr@GLIBC_2.2.5 (2)
> > 69: 0000000000601050    41 IFUNC   GLOBAL DEFAULT   26 strchr@@GLIBC_2.2.5
> > 
> 
> This is a linker bug. Please report it to Ubuntu. Undefined
> functions should never be marked as IFUNC.
> 

Comment 22 H.J. Lu 2010-03-29 15:01:53 UTC
(In reply to comment #21)
> OK, I'm going to transfer this problem to Ubuntu.
> The linker is GNU ld in package binutils, isn't it ?
> 

There may be 2 linkers. In any case, just report it
to Ubuntu.

Comment 23 Matthias Klose 2010-03-29 16:48:52 UTC
only seen with gold (2.20.1). gold from the trunk does work.
Comment 24 Eric CABRET 2010-03-29 20:44:06 UTC
I checked on my Ubuntu 64bit Lucid Lynx system that generates bad binary :
1) binutils (2.20.1-3ubuntu1) is installed
2) binutils-gold (2.20-0ubuntu2) is NOT installed

(In reply to comment #23)
> only seen with gold (2.20.1). gold from the trunk does work.
> 
Comment 25 Eric CABRET 2010-03-29 21:48:11 UTC
I've reported this problem to Ubuntu at this following URL :
https://bugs.launchpad.net/ubuntu/+bug/551245