Skip to contentSkip to conversation

undefined reference to `__lshrdi3' error with GCC 4.0

DISCUSSION Martin Michlmayr 5 participants 9 messages Jan 17, 2006 – Feb 17, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Has anyone else seen the following error when compiling a kernel with GCC 4.0 (GCC 3.3 works) and knows what to do about it?

arch/mips/kernel/built-in.o: In function `time_init':
: undefined reference to __lshrdi3' arch/mips/kernel/built-in.o: In function time_init':
: relocation truncated to fit: R_MIPS_26 against `__lshrdi3'

This problem is also reported at
http://sources.redhat.com/ml/crossgcc/2005-11/msg00194.html but no solution is mentioned.

Signature · 2 lines
Martin Michlmayr
http://www.cyrius.com/
#1 lore raw
Quoted 5 lines · Martin Michlmayr

Has anyone else seen the following error when compiling a kernel with GCC 4.0 (GCC 3.3 works) and knows what to do about it?

arch/mips/kernel/built-in.o: In function `time_init':
: undefined reference to `__lshrdi3'

I think I've solved it by copying the files
ashldi3.c ashrdi3.c lshrdi3.c
from arch/ppc/lib to arch/mips/lib

The patch for 2.6 is:

arch/mips/lib/Makefile +3 -0
index cf12caf..dfa0b12 100644
@@ -7,4 +7,7 @@ lib-y	+= csum_partial_copy.o memcpy.o pr
 
 obj-y	+= iomap.o
 
+#ugly hack. Why is this needed?
+lib-$(CONFIG_MIKROTIK_RB500) += ashldi3.o ashrdi3.o lshrdi3.o
+
 EXTRA_AFLAGS := $(CFLAGS)
arch/mips/lib/ashldi3.c new file +66 -0

66 lines not on this page · raw message

arch/mips/lib/ashrdi3.c new file +68 -0

68 lines not on this page · raw message

arch/mips/lib/lshrdi3.c new file +68 -0

68 lines not on this page · raw message

#2 lore raw
Quoted 10 lines · P. Christeas
Quoted 5 lines · Martin Michlmayr

Has anyone else seen the following error when compiling a kernel with GCC 4.0 (GCC 3.3 works) and knows what to do about it?

arch/mips/kernel/built-in.o: In function `time_init':
: undefined reference to `__lshrdi3'

I think I've solved it by copying the files
ashldi3.c ashrdi3.c lshrdi3.c
from arch/ppc/lib to arch/mips/lib

No such files in arch/ppc/lib? Oh well, doesn't matter.

Quoted 1 line

The patch for 2.6 is:

struct DIstruct seems broken for little endian.

Ralf

#3 lore raw
Quoted 5 lines · Ralf Baechle
Quoted 4 lines · P. Christeas
Quoted 3 lines · Martin Michlmayr

Has anyone else seen the following error when compiling a kernel with GCC 4.0 (GCC 3.3 works) and knows what to do about it?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

arch/mips/kernel/built-in.o: In function `time_init':
: undefined reference to `__lshrdi3'

I think I've solved it by copying the files
ashldi3.c ashrdi3.c lshrdi3.c
from arch/ppc/lib to arch/mips/lib

No such files in arch/ppc/lib? Oh well, doesn't matter.

It was from m68k :S

Quoted 4 lines
Quoted 2 lines

The patch for 2.6 is:

struct DIstruct seems broken for little endian.

What consequences does that have?

Quoted 2 lines

Ralf

#4 lore raw
Quoted 7 lines · P. Christeas
Quoted 1 line

No such files in arch/ppc/lib? Oh well, doesn't matter.

It was from m68k :S

Quoted 3 lines
Quoted 1 line

The patch for 2.6 is:

struct DIstruct seems broken for little endian.

What consequences does that have?

Wrong results of 64-bit shift operations when building with -Os.

Ralf

#5 lore raw
In reply to P. Christeas
Quoted 6 lines · P. Christeas
Quoted 5 lines · Martin Michlmayr

Has anyone else seen the following error when compiling a kernel with GCC 4.0 (GCC 3.3 works) and knows what to do about it?

arch/mips/kernel/built-in.o: In function `time_init':
: undefined reference to `__lshrdi3'

Thanks to Martin Michlmayr's testing I now know this problem is limited to kernels built with gcc 4.0 and newer when optimizing for size.

Quoted 3 lines

I think I've solved it by copying the files
ashldi3.c ashrdi3.c lshrdi3.c
from arch/ppc/lib to arch/mips/lib

There is an awful lot of libgcc bits flying around in the kernel and I guess I'd be flamed for submitting even more ;-) so I tried to come up with something to make most if not all unnecessary. Still needs a little polishing but below for testing and commenting.

Ralf

include/asm-mips/libgcc.h new file +0 -0
new file mode 100644
index 0000000..0aef711
 include/asm-mips/libgcc.h |    8 ++++++++
 include/linux/libgcc.h    |   32 ++++++++++++++++++++++++++++++++
 lib/Makefile              |    1 +
 lib/ashldi3.c             |   32 ++++++++++++++++++++++++++++++++
 lib/ashrdi3.c             |   36 ++++++++++++++++++++++++++++++++++++
 lib/lshrdi3.c             |   34 ++++++++++++++++++++++++++++++++++
 6 files changed, 143 insertions(+)
include/asm-mips/libgcc.h new file +8 -0
Index: linux-mips/include/asm-mips/libgcc.h
===================================================================
@@ -0,0 +1,8 @@
+#ifndef __ASM_LIBGCC_H
+#define __ASM_LIBGCC_H
+
+#define ARCH_NEEDS_ashldi3
+#define ARCH_NEEDS_ashrdi3
+#define ARCH_NEEDS_lshrdi3
+
+#endif /* __ASM_LIBGCC_H */
include/linux/libgcc.h new file +32 -0
Index: linux-mips/include/linux/libgcc.h
===================================================================
@@ -0,0 +1,32 @@
+#ifndef __LINUX_LIBGCC_H
+#define __LINUX_LIBGCC_H
+
+#include <asm/byteorder.h>
+#include <asm/libgcc.h>
+
+typedef long long DWtype;
+typedef int Wtype;
+typedef unsigned int UWtype;
+typedef int word_type __attribute__ ((mode (__word__)));
+
+#define BITS_PER_UNIT 8
+
+#ifdef __BIG_ENDIAN
+struct DWstruct {
+	Wtype high, low;
+};
+#elif defined(__LITTLE_ENDIAN)
+struct DWstruct {
+	Wtype low, high;
+};
+#else
+#error I feel sick.
+#endif
+
+typedef union
+{
+	struct DWstruct s;
+	DWtype ll;
+} DWunion;
+
+#endif /* __LINUX_LIBGCC_H */
lib/Makefile +1 -0
Index: linux-mips/lib/Makefile
===================================================================
@@ -8,6 +8,7 @@ lib-y := errno.o ctype.o string.o vsprin
 	 sha1.o
 
 lib-y	+= kobject.o kref.o kobject_uevent.o klist.o
+lib-y	+= ashldi3.o ashrdi3.o lshrdi3.o
 
 obj-y += sort.o parser.o halfmd4.o
 
lib/ashldi3.c new file +32 -0
Index: linux-mips/lib/ashldi3.c
===================================================================
@@ -0,0 +1,32 @@
+#include <linux/libgcc.h>
+#include <linux/module.h>
+
+#ifdef ARCH_NEEDS_ashldi3
+
+DWtype __ashldi3(DWtype u, word_type b)
+{
+	DWunion uu, w;
+	word_type bm;
+
+	if (b == 0)
+		return u;
+
+	uu.ll = u;
+	bm = (sizeof(Wtype) * BITS_PER_UNIT) - b;
+
+	if (bm <= 0) {
+		w.s.low = 0;
+		w.s.high = (UWtype) uu.s.low << -bm;
+	} else {
+		const UWtype carries = (UWtype) uu.s.low >> bm;
+
+		w.s.low = (UWtype) uu.s.low << b;
+		w.s.high = ((UWtype) uu.s.high << b) | carries;
+	}
+
+	return w.ll;
+}
+
+EXPORT_SYMBOL(__ashldi3);
+
+#endif /* ARCH_NEEDS_ashldi3 */
lib/ashrdi3.c new file +36 -0
Index: linux-mips/lib/ashrdi3.c
===================================================================
@@ -0,0 +1,36 @@
+#include <linux/libgcc.h>
+#include <linux/module.h>
+
+/* Unless shift functions are defined with full ANSI prototypes,
+   parameter b will be promoted to int if word_type is smaller than an int.  */
+#ifdef ARCH_NEEDS_ashrdi3
+
+DWtype __ashrdi3(DWtype u, word_type b)
+{
+	DWunion uu, w;
+	word_type bm;
+
+	if (b == 0)
+		return u;
+
+	uu.ll = u;
+	bm = (sizeof(Wtype) * BITS_PER_UNIT) - b;
+
+	if (bm <= 0) {
+		/* w.s.high = 1..1 or 0..0 */
+		w.s.high =
+		    uu.s.high >> (sizeof(Wtype) * BITS_PER_UNIT - 1);
+		w.s.low = uu.s.high >> -bm;
+	} else {
+		const UWtype carries = (UWtype) uu.s.high << bm;
+
+		w.s.high = uu.s.high >> b;
+		w.s.low = ((UWtype) uu.s.low >> b) | carries;
+	}
+
+	return w.ll;
+}
+
+EXPORT_SYMBOL(__ashrdi3);
+
+#endif /* ARCH_NEEDS_ashrdi3 */
lib/lshrdi3.c new file +34 -0
Index: linux-mips/lib/lshrdi3.c
===================================================================
@@ -0,0 +1,34 @@
+#include <linux/libgcc.h>
+#include <linux/module.h>
+
+/* Unless shift functions are defined with full ANSI prototypes,
+   parameter b will be promoted to int if word_type is smaller than an int.  */
+#ifdef ARCH_NEEDS_lshrdi3
+
+DWtype __lshrdi3(DWtype u, word_type b)
+{
+	DWunion uu, w;
+	word_type bm;
+
+	if (b == 0)
+		return u;
+
+	uu.ll = u;
+	bm = (sizeof(Wtype) * BITS_PER_UNIT) - b;
+
+	if (bm <= 0) {
+		w.s.high = 0;
+		w.s.low = (UWtype) uu.s.high >> -bm;
+	} else {
+		const UWtype carries = (UWtype) uu.s.high << bm;
+
+		w.s.high = (UWtype) uu.s.high >> b;
+		w.s.low = ((UWtype) uu.s.low >> b) | carries;
+	}
+
+	return w.ll;
+}
+
+EXPORT_SYMBOL(__lshrdi3);
+
+#endif /* ARCH_NEEDS_lshrdi3 */
#6 lore raw
Quoted 4 lines · Ralf Baechle

There is an awful lot of libgcc bits flying around in the kernel and I guess I'd be flamed for submitting even more ;-) so I tried to come up with something to make most if not all unnecessary. Still needs a little polishing but below for testing and commenting.

People will love you for that. I also already added libgcc functions:-)

include/linux/libgcc.h line 24

Quoted 11 lines
include/linux/libgcc.h new file +11 -0
+#ifdef __BIG_ENDIAN
+struct DWstruct {
+	Wtype high, low;
+};
+#elif defined(__LITTLE_ENDIAN)
+struct DWstruct {
+	Wtype low, high;
+};
+#else
+#error I feel sick.
+#endif

No, you feel PDP11ish. Though you'd put quotes about the warning message.

I'm all for adding this!

MfG, JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 für einen Freien Staat voll Freier Bürger"  | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#7 lore raw
Quoted 6 lines · Jan-Benedict Glaw

include/linux/libgcc.h line 24

Quoted 3 lines
include/linux/libgcc.h new file +3 -0
+#else
+#error I feel sick.
+#endif

No, you feel PDP11ish. Though you'd put quotes about the warning message.

No, you wouldn't.

drow@nevyn:~% echo '#error A B' | gcc -E -
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
<stdin>:1:2: error: #error A B
drow@nevyn:~% echo '#error "A B"' | gcc -E -
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
<stdin>:1:2: error: #error "A B"
drow@nevyn:~%

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery
#8 lore raw
In reply to Ralf Baechle
Quoted 5 lines · Ralf Baechle
Quoted 2 lines
Quoted 2 lines

arch/mips/kernel/built-in.o: In function `time_init':
: undefined reference to `__lshrdi3'

Thanks to Martin Michlmayr's testing I now know this problem is limited to kernels built with gcc 4.0 and newer when optimizing for size.

...

Quoted 4 lines

There is an awful lot of libgcc bits flying around in the kernel and I guess I'd be flamed for submitting even more ;-) so I tried to come up with something to make most if not all unnecessary. Still needs a little polishing but below for testing and commenting.

I think you've cleaned it up in the meantime. Can you please send the patch to lkml as a RFC?

Signature · 2 lines
Martin Michlmayr
http://www.cyrius.com/