Skip to contentSkip to conversation

mini-os: link to libgcc.a to fix build with gcc7

PATCH In review Olaf Hering 3 participants 8 messages Jun 26, 2017 – Jun 30, 2017 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mini-os: link to libgcc.a to fix build with gcc7

gcc7 generates a call to __udivmoddi4 ...

stubdom/mini-os-x86_32-grub/mini-os.o: In function `_strtoll_r':
stubdom/newlib-x86_32/i686-xen-elf/newlib/libc/stdlib/../../../../../newlib-1.16.0/newlib/libc/stdlib/strtoll_r.c:110: undefined reference to `__udivmoddi4' make[2]: *** [Makefile:167: stubdom/mini-os-x86_32-grub/mini-os] Error 1

... which the linker only finds if libgcc.a is provided on the commandline.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index ef8559b..b9c1336 100644
@@ -162,7 +162,7 @@ $(OBJ_DIR)/arch/x86/minios-x86%.lds:  arch/x86/minios-x86.lds.S
 	$(CPP) $(ASFLAGS) -P $< -o $@
 
 $(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
-	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o [email protected]
+	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) $$(gcc -print-libgcc-file-name $(CFLAGS)) -o [email protected]
 	$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start [email protected] [email protected]
 	$(LD) $(LDFLAGS) $(LDFLAGS_FINAL) [email protected] $(EXTRA_OBJS) -o $@
 	gzip -f -9 -c $@ >[email protected]

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw

CC minios-devel

Quoted 18 lines · Olaf Hering

gcc7 generates a call to __udivmoddi4 ...

stubdom/mini-os-x86_32-grub/mini-os.o: In function `_strtoll_r':
stubdom/newlib-x86_32/i686-xen-elf/newlib/libc/stdlib/../../../../../newlib-1.16.0/newlib/libc/stdlib/strtoll_r.c:110: undefined reference to `__udivmoddi4' make[2]: *** [Makefile:167: stubdom/mini-os-x86_32-grub/mini-os] Error 1

... which the linker only finds if libgcc.a is provided on the commandline.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index ef8559b..b9c1336 100644

Makefile $(OBJ_DIR)/arch/x86/minios-x86%.lds: arch/x86/minios-x86.lds.S · line 165

Quoted 5 lines
Makefile +1 -1
@@ -162,7 +162,7 @@ $(OBJ_DIR)/arch/x86/minios-x86%.lds:  arch/x86/minios-x86.lds.S
 	$(CPP) $(ASFLAGS) -P $< -o $@
 
 $(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
-	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o [email protected]
+	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) $$(gcc -print-libgcc-file-name $(CFLAGS)) -o [email protected]

Append it to LDLIBS?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 23 lines · Wei Liu

CC minios-devel

Quoted 20 lines · Olaf Hering

gcc7 generates a call to __udivmoddi4 ...

stubdom/mini-os-x86_32-grub/mini-os.o: In function `_strtoll_r':
stubdom/newlib-x86_32/i686-xen-elf/newlib/libc/stdlib/../../../../../newlib-1.16.0/newlib/libc/stdlib/strtoll_r.c:110: undefined reference to `__udivmoddi4' make[2]: *** [Makefile:167: stubdom/mini-os-x86_32-grub/mini-os] Error 1

... which the linker only finds if libgcc.a is provided on the commandline.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index ef8559b..b9c1336 100644
@@ -162,7 +162,7 @@ $(OBJ_DIR)/arch/x86/minios-x86%.lds:  arch/x86/minios-x86.lds.S
 	$(CPP) $(ASFLAGS) -P $< -o $@
 
Quoted 5 lines

Makefile $(OBJ_DIR)/arch/x86/minios-x86%.lds: arch/x86/minios-x86.lds.S · line 165

Quoted 3 lines
Makefile +1 -1
 $(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
-	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o [email protected]
+	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) $$(gcc -print-libgcc-file-name $(CFLAGS)) -o [email protected]

Append it to LDLIBS?

This will break compilation with non-gcc.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 24 lines · Roger Pau Monné
Quoted 23 lines · Wei Liu

CC minios-devel

Quoted 20 lines · Olaf Hering

gcc7 generates a call to __udivmoddi4 ...

stubdom/mini-os-x86_32-grub/mini-os.o: In function `_strtoll_r':
stubdom/newlib-x86_32/i686-xen-elf/newlib/libc/stdlib/../../../../../newlib-1.16.0/newlib/libc/stdlib/strtoll_r.c:110: undefined reference to `__udivmoddi4' make[2]: *** [Makefile:167: stubdom/mini-os-x86_32-grub/mini-os] Error 1

... which the linker only finds if libgcc.a is provided on the commandline.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index ef8559b..b9c1336 100644
@@ -162,7 +162,7 @@ $(OBJ_DIR)/arch/x86/minios-x86%.lds:  arch/x86/minios-x86.lds.S
 	$(CPP) $(ASFLAGS) -P $< -o $@
 
Quoted 8 lines
Quoted 5 lines

Makefile $(OBJ_DIR)/arch/x86/minios-x86%.lds: arch/x86/minios-x86.lds.S · line 165

Quoted 3 lines
Makefile +1 -1
 $(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
-	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o [email protected]
+	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) $$(gcc -print-libgcc-file-name $(CFLAGS)) -o [email protected]

Append it to LDLIBS?

This will break compilation with non-gcc.

I thought about that but mini-os is Linux only? I've tried to build it on FreeBSD.

If I was wrong, then we should tell gcc to not generate code that relies on libgcc. That seems impossible by reading the doc...

Quoted 1 line

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 31 lines · Wei Liu
Quoted 30 lines · Roger Pau Monné
Quoted 28 lines · Wei Liu

CC minios-devel

Quoted 18 lines · Olaf Hering

gcc7 generates a call to __udivmoddi4 ...

stubdom/mini-os-x86_32-grub/mini-os.o: In function `_strtoll_r':
stubdom/newlib-x86_32/i686-xen-elf/newlib/libc/stdlib/../../../../../newlib-1.16.0/newlib/libc/stdlib/strtoll_r.c:110: undefined reference to `__udivmoddi4' make[2]: *** [Makefile:167: stubdom/mini-os-x86_32-grub/mini-os] Error 1

... which the linker only finds if libgcc.a is provided on the commandline.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index ef8559b..b9c1336 100644

Makefile $(OBJ_DIR)/arch/x86/minios-x86%.lds: arch/x86/minios-x86.lds.S · line 165

Quoted 5 lines
Makefile +1 -1
@@ -162,7 +162,7 @@ $(OBJ_DIR)/arch/x86/minios-x86%.lds:  arch/x86/minios-x86.lds.S
 	$(CPP) $(ASFLAGS) -P $< -o $@
 
 $(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
-	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o [email protected]
+	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) $$(gcc -print-libgcc-file-name $(CFLAGS)) -o [email protected]

Append it to LDLIBS?

Quoted 5 lines
Quoted 2 lines

This will break compilation with non-gcc.

I thought about that but mini-os is Linux only? I've tried to build it on FreeBSD.

It is Linux only, but you can also use clang on Linux? FWIW, I've heard someone managed to compile this on NetBSD.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 32 lines · Roger Pau Monné
Quoted 31 lines · Wei Liu
Quoted 30 lines · Roger Pau Monné
Quoted 28 lines · Wei Liu

CC minios-devel

Quoted 18 lines · Olaf Hering

gcc7 generates a call to __udivmoddi4 ...

stubdom/mini-os-x86_32-grub/mini-os.o: In function `_strtoll_r':
stubdom/newlib-x86_32/i686-xen-elf/newlib/libc/stdlib/../../../../../newlib-1.16.0/newlib/libc/stdlib/strtoll_r.c:110: undefined reference to `__udivmoddi4' make[2]: *** [Makefile:167: stubdom/mini-os-x86_32-grub/mini-os] Error 1

... which the linker only finds if libgcc.a is provided on the commandline.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index ef8559b..b9c1336 100644

Makefile $(OBJ_DIR)/arch/x86/minios-x86%.lds: arch/x86/minios-x86.lds.S · line 165

Quoted 5 lines
Makefile +1 -1
@@ -162,7 +162,7 @@ $(OBJ_DIR)/arch/x86/minios-x86%.lds:  arch/x86/minios-x86.lds.S
 	$(CPP) $(ASFLAGS) -P $< -o $@
 
 $(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
-	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o [email protected]
+	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) $$(gcc -print-libgcc-file-name $(CFLAGS)) -o [email protected]

Append it to LDLIBS?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This will break compilation with non-gcc.

I thought about that but mini-os is Linux only? I've tried to build it on FreeBSD.

It is Linux only, but you can also use clang on Linux? FWIW, I've heard someone managed to compile this on NetBSD.

On second thought I don't think we want to make this worse. So the change in this patch should be conditional on gcc.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
Quoted 2 lines · Wei Liu

On second thought I don't think we want to make this worse. So the change in this patch should be conditional on gcc.

How whould I check for gcc in the Makefile?
In xen.git I see a conditional for clang. I dont have a clang at hand, perhaps it knows about "-print-libgcc-file-name"?

Olaf

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw
Quoted 8 lines · Olaf Hering
Quoted 2 lines · Wei Liu

On second thought I don't think we want to make this worse. So the change in this patch should be conditional on gcc.

How whould I check for gcc in the Makefile?
In xen.git I see a conditional for clang. I dont have a clang at hand, perhaps it knows about "-print-libgcc-file-name"?

Mine works fine:

 $  gcc -print-libgcc-file-name
/usr/lib64/gcc/x86_64-suse-linux/7/libgcc.a
 $  clang-3.8 -print-libgcc-file-name
/usr/bin/../lib64/gcc/x86_64-suse-linux/7/libgcc.a

Olaf

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel