Skip to contentSkip to conversation

klibc sparc trouble with gcc > 4.0

PATCH maximilian attems 4 participants 4 messages Nov 5, 2007 – Nov 9, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw

tried below fix, that is a partial revert of klibc 6fbd8fafdcc793135988733996d72b0298afe934
see git://git.kernel.org/pub/scm/libs/klibc/klibc.git
with belows fix klibc compiles fine on sparc with newer gcc, but segfaults:

titan:~# strace -vfF /usr/lib/klibc/bin/fstype
execve("/usr/lib/klibc/bin/fstype", ["/usr/lib/klibc/bin/fstype"],
["SHELL=/bin/bash", "TERM=xterm", "SSH_CLIENT=[myip] 39403"...,
"SSH_TTY=/dev/pts/0", "USER=root",
"LS_COLORS=no:fi:di;34:l"...,
"PATH=/usr/local/sbin:/usr/local/"..., "MAIL=/var/mail/root",
"PWD=/root", "LANG=en_US.UTF-8", "PS1=\\h:\\w\\$ ", "HOME=/root",
"SHLVL=2", "LS_OPTIONS=--color=auto", "LOGNAME=root",
"SSH_CONNECTION=[myip] 3"..., "_=/usr/bin/strace", "OLDPWD=/"]) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Process 3636 detached

thanks for looking at it.

Signature · 7 lines
maks



use our own clzdi on sparc instead the one of libgcc

Signed-off-by: maximilian attems <[email protected]>
usr/klibc/arch/sparc64/Kbuild +1 -1
index 2854f69..f2450a2 100644
@@ -2,7 +2,7 @@
 # klibc files for sparc64
 #
 
-klib-y := pipe.o setjmp.o syscall.o sysfork.o
+klib-y := pipe.o setjmp.o syscall.o sysfork.o ../../libgcc/__clzdi2.o
 
 always  := crt0.o
 targets := crt0.o
usr/klibc/libgcc/__clzdi2.c new file +23 -0
new file mode 100644
index 0000000..13e636c
@@ -0,0 +1,23 @@
+/*
+ * __clzdi2 - Returns the leading number of 0 bits in the argument
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+
+uint64_t __clzdi2(uint64_t v)
+{
+	uint32_t vhi = (uint32_t) (v >> 32);
+	uint32_t vx;
+	int dp;
+
+	if (vhi) {
+		vx = vhi;
+		dp = 0;
+	} else {
+		vx = (uint32_t) v;
+		dp = 32;
+	}
+
+	return dp + __builtin_clz(vx);
+}
#1 lore raw

= Mon, Nov 05, 2007 at 02:55:45PM +0100, maximilian attems = []

killed by SIGSEGV +++

Quoted 11 lines
titan:~# strace -vfF /usr/lib/klibc/bin/fstype
execve("/usr/lib/klibc/bin/fstype", ["/usr/lib/klibc/bin/fstype"],
["SHELL=/bin/bash", "TERM=xterm", "SSH_CLIENT=[myip] 39403"...,
"SSH_TTY=/dev/pts/0", "USER=root",
"LS_COLORS=no:fi:di;34:l"...,
"PATH=/usr/local/sbin:/usr/local/"..., "MAIL=/var/mail/root",
"PWD=/root", "LANG=en_US.UTF-8", "PS1=\\h:\\w\\$ ", "HOME=/root",
"SHLVL=2", "LS_OPTIONS=--color=auto", "LOGNAME=root",
"SSH_CONNECTION=[myip] 3"..., "_=/usr/bin/strace", "OLDPWD=/"]) = 0
killed by SIGSEGV +++ renamed from SIGSEGV (Segmentation fault) @ 0 (0) --- +0 -0

gdb doesn't work/help?

[]

killed by SIGSEGV +++ line 10

Quoted 12 lines

+++ b/usr/klibc/libgcc/__clzdi2.c

killed by SIGSEGV +++ renamed from SIGSEGV (Segmentation fault) @ 0 (0) --- +10 -0
@@ -0,0 +1,23 @@
+/*
+ * __clzdi2 - Returns the leading number of 0 bits in the argument
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+
+uint64_t __clzdi2(uint64_t v)
+{
+	uint32_t vhi = (uint32_t) (v >> 32);

v' is a data in memory loaded to register to perform shift, thus this operation yields high 32-bits part of v'

killed by SIGSEGV +++ line 18

Quoted 8 lines
killed by SIGSEGV +++ renamed from SIGSEGV (Segmentation fault) @ 0 (0) --- +8 -0
+	uint32_t vx;
+	int dp;
+
+	if (vhi) {
+		vx = vhi;
+		dp = 0;
+	} else {
+		vx = (uint32_t) v;

v' is a data in memory, accessed with 32-bits cast, thus operation yields high 32-bits part of v'.

killed by SIGSEGV +++ line 23

Quoted 5 lines
killed by SIGSEGV +++ renamed from SIGSEGV (Segmentation fault) @ 0 (0) --- +5 -0
+		dp = 32;
+	}
+
+	return dp + __builtin_clz(vx);
+}

While i didn't see/used any big-endian machine/asm_dump, i just speculate, since noone replied yet.
____

#2 lore raw
In reply to maximilian attems
Quoted 12 lines · Oleg Verych

usr/klibc/libgcc/__clzdi2.c line 18

Quoted 8 lines
usr/klibc/libgcc/__clzdi2.c new file +8 -0
+	uint32_t vx;
+	int dp;
+
+	if (vhi) {
+		vx = vhi;
+		dp = 0;
+	} else {
+		vx = (uint32_t) v;

v' is a data in memory, accessed with 32-bits cast, thus operation yields high 32-bits part of v'.

Bullsh*t. That would be *(uint32_t *)&v. Casting between integer types truncate the high bits regardless of platform endianness.

-hpa

#3 lore raw
In reply to maximilian attems
Quoted 15 lines · Oleg Verych

= Mon, Nov 05, 2007 at 02:55:45PM +0100, maximilian attems = []

killed by SIGSEGV +++

Quoted 11 lines
titan:~# strace -vfF /usr/lib/klibc/bin/fstype
execve("/usr/lib/klibc/bin/fstype", ["/usr/lib/klibc/bin/fstype"],
["SHELL=/bin/bash", "TERM=xterm", "SSH_CLIENT=[myip] 39403"...,
"SSH_TTY=/dev/pts/0", "USER=root",
"LS_COLORS=no:fi:di;34:l"...,
"PATH=/usr/local/sbin:/usr/local/"..., "MAIL=/var/mail/root",
"PWD=/root", "LANG=en_US.UTF-8", "PS1=\\h:\\w\\$ ", "HOME=/root",
"SHLVL=2", "LS_OPTIONS=--color=auto", "LOGNAME=root",
"SSH_CONNECTION=[myip] 3"..., "_=/usr/bin/strace", "OLDPWD=/"]) = 0
killed by SIGSEGV +++ renamed from SIGSEGV (Segmentation fault) @ 0 (0) --- +0 -0

gdb doesn't work/help?

(gdb) where
#0 0x8000faac in ?? ()
#1 0x8000facc in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Not sure if this is a gdb problem, though - never even tried to debug klibc. With the mentioned patch klibc compiles, but all utils just segfault, strace is as short as seen above.

Quoted 8 lines

[]

killed by SIGSEGV +++ line 4

Quoted 6 lines

+++ b/usr/klibc/libgcc/__clzdi2.c

killed by SIGSEGV +++ renamed from SIGSEGV (Segmentation fault) @ 0 (0) --- +4 -0
@@ -0,0 +1,23 @@
+/*
+ * __clzdi2 - Returns the leading number of 0 bits in the argument
+ */
+

without this patch it doesn't compile at all:

KLIBCLD usr/klibc/libc.so
ld: sparc architecture of input file `/usr/lib/gcc/sparc-linux-gnu/4.2.3/libgcc.a(_clzdi2.o)' is incompatible with sparc:v9 output
ld: sparc architecture of input file /usr/lib/gcc/sparc-linux-gnu/4.2.3/libgcc.a(_clz.o)' is incompatible with sparc:v9 output /usr/lib/gcc/sparc-linux-gnu/4.2.3/libgcc.a(_clzdi2.o): In function __clzdi2':
(.text+0xc): undefined reference to _GLOBAL_OFFSET_TABLE_' /usr/lib/gcc/sparc-linux-gnu/4.2.3/libgcc.a(_clzdi2.o): In function __clzdi2':
(.text+0x14): undefined reference to `_GLOBAL_OFFSET_TABLE_' make[3]: *** [usr/klibc/libc.so] Error 1
make[2]: *** [all] Error 2
make[1]: *** [klibc] Error 2
make[1]: Leaving directory `/root/klibc-1.5.7'

Signature · 2 lines
Bernd Zeimetz
<[email protected]>                         <http://bzed.de/>