Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 195717 - mysql-5.0.44-r1 bus error in gethostbyname_r on sparc with gcc-4.2.1
Summary: mysql-5.0.44-r1 bus error in gethostbyname_r on sparc with gcc-4.2.1
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: Sparc Linux
: High normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: unaligned-access
  Show dependency tree
 
Reported: 2007-10-13 16:25 UTC by Dan Callaghan
Modified: 2023-05-08 17:26 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
sparc-stack-arrays-auto-aligment.patch (sparc-stack-arrays-auto-aligment.patch,651 bytes, patch)
2007-10-18 17:14 UTC, Jose Luis Rivero (yoswink) (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Callaghan 2007-10-13 16:25:39 UTC
dan@lem ~ $ cat mytest.c
#include <stdlib.h>
#include <mysql/mysql.h>

int main(int argc, char *argv[]) {
        MYSQL cn;
        mysql_init(&cn);
        mysql_real_connect(&cn, "someserver", "user", "pass", "db", 0, NULL, 0);
        return 0;
}
dan@lem ~ $ gcc -g -o mytest mytest.c -lmysqlclient_r
dan@lem ~ $ ./mytest
Bus error


(gdb) where
#0  0xf7c27928 in internal_getent (result=0xffee6fbc, buffer=0xffee669a "\177", buflen=2048, errnop=0xf7fd32fc, herrnop=0xffee6fe0, af=2, flags=0) at nss_files/files-hosts.c:50
#1  0xf7c28264 in _nss_files_gethostbyname_r (name=0x10738 "someserver", result=0xffee6fbc, buffer=0xffee669a "\177", buflen=2048, errnop=0xf7fd32fc, herrnop=0xffee6fe0) at nss_files/files-hosts.c:265
#2  0xf7ec39e0 in __gethostbyname_r (name=0x10738 "someserver", resbuf=0xffee6fbc, buffer=0xffee669a "\177", buflen=2048, result=0xffee6614, h_errnop=0xffee6fe0) at ../nss/getXXbyYY_r.c:207
#3  0xf7f53398 in my_gethostbyname_r () from /usr/lib/libmysqlclient_r.so.15
#4  0xf7f5fe58 in mysql_real_connect () from /usr/lib/libmysqlclient_r.so.15
#5  0x000105e4 in main (argc=1, argv=0xffee7514) at mytest.c:8


The problem seems to be the buffer argument to gethostbyname_r, which is not aligned. Here is a simpler program that demonstrates the problem outside of mysql (buffer length 2050 causes gcc to place buff at an unaligned address, also -O is needed):


dan@lem ~ $ cat test.c 
#include <stdio.h>
#include <unistd.h>
#include <netdb.h>

int main() {
        char buff[2050];
        struct hostent ent;
        struct hostent *ret;
        int errno;
        gethostbyname_r("someserver", &ent, buff, 2050, &ret, &errno);
        return errno;
}
dan@lem ~ $ gcc -g -O -o test test.c
dan@lem ~ $ ./test 
Bus error


(gdb) where
#0  0xf7d9b928 in internal_getent (result=0xffd6ac00, buffer=0xffd6ac16 "\177", buflen=2050, errnop=0xf7f1668c, herrnop=0xffd6abf8, af=2, flags=0) at nss_files/files-hosts.c:50
#1  0xf7d9c264 in _nss_files_gethostbyname_r (name=0x105f8 "someserver", result=0xffd6ac00, buffer=0xffd6ac16 "\177", buflen=2050, errnop=0xf7f1668c, herrnop=0xffd6abf8) at nss_files/files-hosts.c:265
#2  0xf7eab9e0 in __gethostbyname_r (name=0x105f8 "someserver", resbuf=0xffd6ac00, buffer=0xffd6ac16 "\177", buflen=2050, result=0xffd6abfc, h_errnop=0xffd6abf8) at ../nss/getXXbyYY_r.c:207
#3  0x000104a4 in main () at test.c:10


Probably connected with this GCC bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33594
Comment 1 Dan Callaghan 2007-10-13 16:26:13 UTC
emerge --info:

Portage 2.1.3.9 (default-linux/sparc/sparc64/2007.0, gcc-4.2.1, glibc-2.5-r4, 2.6.22-gentoo-r5-LEM sparc64)
=================================================================
System uname: 2.6.22-gentoo-r5-LEM sparc64 sun4v
Timestamp of tree: Sat, 13 Oct 2007 15:20:01 +0000
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p17
dev-lang/python:     2.5.1-r2
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 1.12.9-r2
sys-apps/sandbox:    1.2.17
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10
sys-devel/binutils:  2.17-r1
sys-devel/gcc-config: 1.3.16
sys-devel/libtool:   1.5.24
virtual/os-headers:  2.6.21
ACCEPT_KEYWORDS="sparc"
CBUILD="sparc-unknown-linux-gnu"
CFLAGS="-Os -mcpu=niagara -mvis -pipe"
CHOST="sparc-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/X11/xkb"
CONFIG_PROTECT_MASK="/etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/terminfo"
CXXFLAGS="-Os -mcpu=niagara -mvis -pipe"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS=""
FEATURES="ccache distlocks metadata-transfer parallel-fetch sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://ftp.swin.edu.au/gentoo http://public.planetmirror.com/pub/gentoo http://distfiles.gentoo.org"
LANG="en_AU.utf8"
LC_ALL="en_AU.utf8"
LDFLAGS="-Wl,-O1"
MAKEOPTS="-j32"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --filter=H_**/files/digest-*"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage/djc"
SYNC="rsync://rsync.au.gentoo.org/gentoo-portage"
USE="acl apache2 bash-completion bitmap-fonts bzip2 cli cracklib dri gdbm gnome iconv ipv6 isdnlog kerberos ldap midi mudflap mysql ncurses nls nptl nptlonly openmp pam pcre ppds pppd python readline reflection samba session sparc spl sqlite sqlite3 ssl svg threads truetype-fonts type1-fonts unicode xattr xorg zlib" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU" VIDEO_CARDS="dummy fbdev glint mach64 mga r128 radeon sunbw2 suncg14 suncg3 suncg6 sunffb sunleo tdfx v4l voodoo"
Unset:  CTARGET, INSTALL_MASK, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 2 Jose Luis Rivero (yoswink) (RETIRED) gentoo-dev 2007-10-18 17:12:02 UTC
@Dan:

All your assumptions seems to be right so you did the hard work.

I just backported the patch already in gcc trunk[1] and make a patch for our current gcc: 4.2.1.

If you want to test it, download the experimental ebuild:
http://dev.gentoo.org/~yoswink/tmp/gcc-4.1.2-r1.ebuild

and put the patch in $FILES/4.1.0/:
http://dev.gentoo.org/~yoswink/tmp/sparc-stack-arrays-auto-aligment.patch

Be careful, it could eat your mother-in-law ;)
If after this patch the error is fixed, we'll call our gcc ninjas to include the patch in the tree.

Thanks for reporting and searching the patch.

[1] http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129385
Comment 3 Jose Luis Rivero (yoswink) (RETIRED) gentoo-dev 2007-10-18 17:14:29 UTC
Created attachment 133793 [details, diff]
sparc-stack-arrays-auto-aligment.patch

Attach the patch again 4.1.2 just for the records.

P.D: sorry, in the previous comment I wrote 4.2.1, the correct is 4.1.2
Comment 4 Ferris McCormick (RETIRED) gentoo-dev 2008-04-11 15:48:42 UTC
This looks like a toolchain bug to me.  Sparc hardly ever fixes gcc beyond suggesting patches.  Ther's a trivial one attached, and LabMonkey can verify that this problem is present in mysql-5.0.54 built with gcc-4.1.2.

If we have a gcc-4.1.2-r1 which includes this patch, we'll test it.
Comment 5 SpanKY gentoo-dev 2008-04-11 16:44:59 UTC
yes, but we dont go adding arch-specific patches unless the arch in question OKs things first

in this case the patch should be fine since it actually came from upstream gcc and people have validated (they have right?) that it works for them with the versions of gcc in question
Comment 6 Ferris McCormick (RETIRED) gentoo-dev 2008-04-11 16:50:53 UTC
Actually, I'll test this as time permits.  Most likely, next week (I made my own gcc-4.1.2.ebuild which applies the patch.  Patch does apply correctly; it's just a matter of testing the compiler.)
Comment 7 Chris Lee 2008-04-12 17:36:15 UTC
I've tested and confirmed that the supplied patch corrects this issue on my netra.

gcc-4.1.2 as described above and mysql-5.0.54

Without the patched gcc, building mysql with -O1 in CFLAGS will avoid the bus error.  After patching gcc and rebuilding mysql with -O2 at first I thought the problem still existed but then realized that I was still using distcc and that my helper machines did not have the patched gcc.  I rebuilt mysql without distcc, with -O2, and with the patched gcc-4.1.2 and all appears to be well now.
Comment 8 Ferris McCormick (RETIRED) gentoo-dev 2008-04-18 15:30:29 UTC
Patch is good for gcc-4.1.2
Comment 9 SpanKY gentoo-dev 2008-12-27 07:14:33 UTC
this is in gcc-4.3.2 ... do you guys still want this in 4.1.2 ?  i dont really plan on making a new -r# for 4.1.2 at this point ...