Red Hat Bugzilla – Bug 3777
Segmentation fault in simple program
Last modified: 2008-05-01 11:37:50 EDT
The following simple program when executed gives a
segmentation violation. This occurs if the -O2 option is
used. The problem also occurs in RedHat 5.2 with g++ -O
int main ()
double etam, etapm, v1, v2, norm;
double B = 158.024;
double a = 1.0076;
double z = 1.47107;
double smass = 1.445;
double factor = 4.0 / 3.0 * pow (4.0 * M_PI, 0.25) * B;
etam = factor;
printf ("%g", etam);
etam = factor * pow (etam, 0.75);
etapm = factor * pow (etapm, 0.75);
verified - 28 JUN 1999 DLT
------- Additional Comments From 07/09/99 17:56 -------
I tried the same example with gcc-2.96 19990708 (experimental)
which is the development version from egcs.cygnus.com. The bug did
not occur. Ordinarily I would probably still want to know whether
the bug was really fixed or whether it just stopped showing up on
this particular example, but since the IA32 egcs backend has been rewritten I don't know. I can work on trying to find a patch to egcs 1.1.2 if desired (I already spent time in this direction, although I didn't get very far).
Assigned to kingdon. Thsi should be fixed for egcs 1.1.2
*** Bug 4074 has been marked as a duplicate of this bug. ***
This bug was reported by Andrew V. Nikulin
I have the patch file saved in my home directory. The
tarball is called pam_patch.tgz --MJG
"I discovered a serious enough bug in pwdb and pam packages.
So, yesterday I've killed the entire day trying to
understand why sshd2 doesn't work correctly on my Ultra
SPARC box, but it works fine on Intel (both under RedHat
Linux 6.0). After a few sessions with ltrace, gdb and other
tools I've finally understood that a problem appears only
when MD5 hashes are enabled in pam_pwdb module.
Digging sources of pam_pwdb, pwdb and sshd2 I've got next
thing: pwdb and pam use their own routine crypt_md5() for
MD5 calculation, but sshd2 uses standart crypt() from GLIBC
for such purpose.
I wrote a short test program, which simply encrypts the
phrase "magic_word" with salt "$1$xx", calling GLIBC crypt()
and pam_pwdb crypt_md5(). After running this program on SUN
and Intel I've got the following results:
pam_pwdb crypt_md5(): $1$xx$ipOG9IJsAo23Ba44.YOUd1
GLIBC crypt(): $1$xx$ipOG9IJsAo23Ba44.YOUd1
pam_pwdb crypt_md5(): $1$xx$tcVZsr28tzKG890dmISsL/
GLIBC crypt(): $1$xx$ipOG9IJsAo23Ba44.YOUd1
My God! - pam_pwdb crypt_md5() makes different hashes
depending on hardware platform.
Finally, I've got that the problem lies in an incorrect
detection of a byte order for the
architecture. Please, look at
pam-0.66/modules/pam_pwdb/md5.c:22, here is an
attempt to understand the byte order by checking the
presence of HIGHFIRST definition. I had simply replaced
that string with
#if __BYTE_ORDER != __BIG_ENDIAN
and included an appropriate file endiand.h. Such changes I
had applied to pam-0.66/modules/pam_radius/md5.c and
pwdb-0.58/libpwdb/radius/md5.c too. After rebuilding and
reinstalling packages everything works fine on both
Ultra SPARC and Intel."
------- Additional Comments From firstname.lastname@example.org 07/16/99 11:49 -------
Matt, can you reply to this message with tar ball attached? TIA
*** Bug 3261 has been marked as a duplicate of this bug. ***
The -malign-double switch no longer functions correctly with
egcs-c++-1.1.2. C++ code compiled with this switch, then
linked, SEGVs; dying somewhere in the streams library. This
is demonstrated with a trivial test program:
using namespace std;
string name, value;
ifstream ifs( "input.dat" );
assert( ifs.good() );
while( ifs >> value >> name )
cout << name << "\t" << value << endl;
return( 0 );
If -O0 is specified, the SEGV generally occurs in the
istream constructor; on the manipulators flush, width or
precision; or operator<<(). Specifying -Ox, x > 0, usually
causes SEGV from ifstream::~ifstream(). Linking -static may
prevent the SEGV in some instances with optimization, but I
have not tested this extensively. Since the failure is a
SEGV, there is little guarantee that the location of the
signal will provide useful information
The platforms tested were:
1. i686 tweaked RH5.2 (to run egcs/pgcc*-1.1.1) upgraded
2. i486 stock RH5.2 upgraded to RH6.0
3. i486 clean install of RH6.0
4. i586 clean install of RH6.0
The -malign-double option worked with egcs*-1.1.1.
There is no apparent negative effect on plain C code
compiled with the -malign-double switch.
The test program and input data file, a makefile, verbose
assembler with diffs, egcs-c++-1.1.2 -v -a output(make.out),
and this description are available from:
------- Additional Comments From 06/04/99 16:39 -------
I failed to specify that -malign-double option worked with egcs*-1.1.1
on RedHat 5.2 with glibc-2.1-0.990222, binutils-22.214.171.124.23-1, and
------- Additional Comments From email@example.com 06/29/99 07:55 -------
This issue has been forwarded to a developer for further action.
This is fixed in egcs-1.1.2-16.
Oops, egcs-1.1.2-16 doesn't have the fix (my fumblefingers in
writing the spec file). However egcs-1.1.2-17 does.
The fix in 1.1.2-17 is wrong, per conversation with Richard Henderson
(it does fix this particular test case but in the wrong way).
There is a new fix in egcs-1.1.2-19.
for a slightly expanded earlyclobber patch (with discussion).
The saga continues at
(this message has to do with gcc 2.96*, not egcs 1.1.2).
The mystery is solved:
Not completely sure about the situation for EGCS 1.1.2.
for another update with yet another revised patch/diagnosis.