Skip to contentSkip to conversation

Check if cc is from apple toolchain

PATCH In review Vladimir 'phcoder' Serbinenko 2 participants 4 messages May 30, 2009 – Jun 16, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 5/18 Check if cc is from apple toolchain

This patch checks if cc is Apple's version and enables additional command line arguments if it is

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#1 lore raw
Quoted 7 lines · Vladimir 'phcoder' Serbinenko

This patch checks if cc is Apple's version and enables additional command line arguments if it is

--
Regards
Vladimir 'phcoder' Serbinenko

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
Makefile.in +11 -1
index e00f9c3..da2ec48 100644
@@ -64,16 +64,22 @@ mkinstalldirs = $(srcdir)/mkinstalldirs
 
 CC = @CC@
 CFLAGS = @CFLAGS@
+ASFLAGS = @ASFLAGS@
 LDFLAGS = @LDFLAGS@
 CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include -Wall -W \
 	 -DGRUB_LIBDIR=\"$(pkglibdir)\"
 TARGET_CC = @TARGET_CC@
 TARGET_CFLAGS = @TARGET_CFLAGS@
+TARGET_ASFLAGS = @TARGET_ASFLAGS@
+TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@
+TARGET_APPLE_CC = @TARGET_APPLE_CC@
+OBJCONV = @OBJCONV@
 TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include \
 	-Wall -W
 TARGET_LDFLAGS = @TARGET_LDFLAGS@
 TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@
 TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@
+TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@
 TARGET_OBJ2ELF = @TARGET_OBJ2ELF@
 EXEEXT = @EXEEXT@
 OBJCOPY = @OBJCOPY@
@@ -186,8 +192,12 @@ build_env.mk: Makefile
 	(\
 	echo "TARGET_CC=$(TARGET_CC)" ; \
 	echo "TARGET_CFLAGS=$(TARGET_CFLAGS)" ; \
-	echo "TARGET_CPPFLAGS=$(TARGET_CPPFLAGS) -I$(pkglibdir)" ; \
+	echo "TARGET_ASFLAGS=$(TARGET_ASFLAGS)" ; \
+	echo "TARGET_CPPFLAGS=$(TARGET_CPPFLAGS) -I$(pkglibdir) -I$(includedir)" ; \
 	echo "STRIP=$(STRIP)" ; \
+	echo "OBJCONV=$(OBJCONV)" ; \
+	echo "TARGET_MODULE_FORMAT=$(TARGET_MODULE_FORMAT)" ; \
+	echo "TARGET_APPLE_CC=$(TARGET_APPLE_CC)" ; \
 	echo "COMMON_ASFLAGS=$(COMMON_ASFLAGS)" ; \
 	echo "COMMON_CFLAGS=$(COMMON_CFLAGS)" ; \
 	echo "COMMON_LDFLAGS=$(COMMON_LDFLAGS)"\
aclocal.m4 +30 -0
index 38a9a4a..10e0ca5 100644
@@ -156,6 +156,36 @@ rm -f conftest*])
 
 AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
 
+dnl check if our compiler is apple cc
+dnl because it requires numerous workarounds
+AC_DEFUN(grub_apple_cc,
+[AC_REQUIRE([AC_PROG_CC])
+AC_MSG_CHECKING([whether our compiler is apple cc])
+AC_CACHE_VAL(grub_cv_apple_cc,
+[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
+  grub_cv_apple_cc=yes
+else
+  grub_cv_apple_cc=no
+fi
+])
+
+AC_MSG_RESULT([$grub_cv_apple_cc])])
+
+dnl check if our target compiler is apple cc
+dnl because it requires numerous workarounds
+AC_DEFUN(grub_apple_target_cc,
+[AC_REQUIRE([AC_PROG_CC])
+AC_MSG_CHECKING([whether our target compiler is apple cc])
+AC_CACHE_VAL(grub_cv_apple_target_cc,
+[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
+  grub_cv_apple_target_cc=yes
+else
+  grub_cv_apple_target_cc=no
+fi
+])
+
+AC_MSG_RESULT([$grub_cv_apple_target_cc])])
+
 
 dnl Later versions of GAS requires that addr32 and data32 prefixes
 dnl appear in the same lines as the instructions they modify, while
conf/i386-pc.rmk +7 -7
index a72d2d2..8385767 100644
@@ -16,31 +16,31 @@ pkglib_IMAGES = boot.img diskboot.img kernel.img pxeboot.img lnxboot.img \
 # For boot.img.
 boot_img_SOURCES = boot/i386/pc/boot.S
 boot_img_ASFLAGS = $(COMMON_ASFLAGS)
-boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00
+boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)7C00
 boot_img_FORMAT = binary
 
 # For pxeboot.img
 pxeboot_img_SOURCES = boot/i386/pc/pxeboot.S
 pxeboot_img_ASFLAGS = $(COMMON_ASFLAGS)
-pxeboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00
+pxeboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)7C00
 pxeboot_img_FORMAT = binary
 
 # For diskboot.img.
 diskboot_img_SOURCES = boot/i386/pc/diskboot.S
 diskboot_img_ASFLAGS = $(COMMON_ASFLAGS)
-diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,8000
+diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)8000
 diskboot_img_FORMAT = binary
 
 # For lnxboot.img.
 lnxboot_img_SOURCES = boot/i386/pc/lnxboot.S
 lnxboot_img_ASFLAGS = $(COMMON_ASFLAGS)
-lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,6000
+lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)6000
 lnxboot_img_FORMAT = binary
 
 # For cdboot.img.
 cdboot_img_SOURCES = boot/i386/pc/cdboot.S
 cdboot_img_ASFLAGS = $(COMMON_ASFLAGS)
-cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00
+cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)7C00
 cdboot_img_FORMAT = binary
 
 # For kernel.img.
@@ -63,9 +63,9 @@ kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
 	machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
 	machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \
 	machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h
-kernel_img_CFLAGS = $(COMMON_CFLAGS)
+kernel_img_CFLAGS = $(COMMON_CFLAGS)  $(TARGET_IMG_CFLAGS)
 kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
-kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
+kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
 kernel_img_FORMAT = binary
 
 MOSTLYCLEANFILES += symlist.c kernel_syms.lst
configure.ac +56 -27

142 lines not on this page · raw message

genmk.rb +5 -0
index abdb8ca..cfe120a 100644
@@ -129,8 +129,13 @@ UNDSYMFILES += #{undsym}
 	sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)
 
 ifneq ($(#{prefix}_EXPORTS),no)
+ifneq ($(TARGET_APPLE_CC),1)
 #{defsym}: #{pre_obj}
 	$(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
+else
+#{defsym}: #{pre_obj}
+	$(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]'  | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
+endif
 endif
 
 #{undsym}: #{pre_obj}
#2 lore raw

aclocal.m4 rm -f conftest*]) · line 161

Quoted 3 lines · Vladimir 'phcoder' Serbinenko
aclocal.m4 +3 -0
+dnl check if our compiler is apple cc
+dnl because it requires numerous workarounds
+AC_DEFUN(grub_apple_cc,

We don't use lowercase names for macros. They could conflict with variable names.

Review

Quoted 3 lines
(quoted diff) +1 -2
-boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)
-Wl,-Ttext,7C00
+boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)7C00

This looks like a hack.

Quoted 1 line

+if test x$grub_cv_apple_target_cc == xyes ; then

Autoconf uses single "=" in test. I believe old versions of bash would not accept "==". I have applied the fix for that.

configure.ac if test "x$TARGET_CFLAGS" = x; then · line 297

Quoted 4 lines
configure.ac +4 -0
+else
+  TARGET_APPLE_CC=0
+# Use linker script if present, otherwise use builtin -N script.
+AC_MSG_CHECKING([for option to link raw image])

The formatting is messed up here.

Quoted 1 line

+AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])

That's out of place.

configure.ac AC_CHECK_FUNCS(__bswapsi2 __bswapdi2) · line 406

Quoted 3 lines
configure.ac +2 -0
+if test "x$TARGET_APPLE_CC" != x1 ; then
 grub_PROG_OBJCOPY_ABSOLUTE
+fi

What's wrong with it? I actually think that we could drop that test entirely and use strip instead of objcopy in i386-pc.

Quoted 1 line

+AC_SUBST(ASFLAGS)

Maybe there is a way to detect Apple by the macros i

Quoted 9 lines

+ifneq ($(TARGET_APPLE_CC),1)
#{defsym}: #{pre_obj}

        $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1

#{mod_name}/' > $@

genmk.rb +3 -0
+else
+#{defsym}: #{pre_obj}
+       $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]'  | sed 's/^

\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
+endif

This goes beyond the "Check if cc is from apple toolchain". It's a separate fix that is not explained. sed can generally do the same things as grep. Is it possible to have an expression that would work for GNU and Apple nm?

I thought somebody would review the patches and object, but in this case, nobody looked :-(

Signature · 2 lines
Regards,
Pavel Roskin
#3 lore raw
Quoted 9 lines · Pavel Roskin

aclocal.m4 rm -f conftest*]) · line 161

Quoted 3 lines · Vladimir 'phcoder' Serbinenko
aclocal.m4 +3 -0
+dnl check if our compiler is apple cc
+dnl because it requires numerous workarounds
+AC_DEFUN(grub_apple_cc,

We don't use lowercase names for macros. They could conflict with variable names.

Thanks you for your comments. Although I usually understand configure scripts I'm not used to write them. Actually I used another test as a template. I'll check which exactly and so we can fix both of them

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +1 -2
-boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)
-Wl,-Ttext,7C00
+boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)7C00

This looks like a hack.

Otherwise we would have to make separate variables for every link address. Would you prefer it with separate variables?

Quoted 6 lines
Quoted 2 lines

+if test x$grub_cv_apple_target_cc == xyes ; then

Autoconf uses single "=" in test. I believe old versions of bash would not accept "==". I have applied the fix for that.

Thanks

Quoted 8 lines

configure.ac if test "x$TARGET_CFLAGS" = x; then · line 297

Quoted 5 lines
configure.ac +4 -0
+else
+  TARGET_APPLE_CC=0
+# Use linker script if present, otherwise use builtin -N script.
+AC_MSG_CHECKING([for option to link raw image])

The formatting is messed up here.

Thanks

Quoted 6 lines

configure.ac AC_CHECK_FUNCS(__bswapsi2 __bswapdi2) · line 406

Quoted 4 lines
configure.ac +2 -0
+if test "x$TARGET_APPLE_CC" != x1 ; then
 grub_PROG_OBJCOPY_ABSOLUTE
+fi

What's wrong with it?

There is no objcopy in Apple's toolchain

Quoted 5 lines
Quoted 2 lines

+AC_SUBST(ASFLAGS)

Maybe there is a way to detect Apple by the macros i

I will look into it

Quoted 16 lines
Quoted 10 lines

+ifneq ($(TARGET_APPLE_CC),1)
#{defsym}: #{pre_obj}

        $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1

#{mod_name}/' > $@

genmk.rb +3 -0
+else
+#{defsym}: #{pre_obj}
+       $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]'  | sed 's/^

\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
+endif

This goes beyond the "Check if cc is from apple toolchain". It's a separate fix that is not explained. sed can generally do the same things as grep. Is it possible to have an expression that would work for GNU and Apple nm?

The modification is actually to remove --defined-only argument and the grep command is here to simulate this --defined-only argument. Perhaps you're right but imo it's better to use --defined-only rather than grep'ing through the output and I don't see why because of secondary compiling platform we should abandon a useful compiling feature on primary platform

Quoted 14 lines

I thought somebody would review the patches and object, but in this case, nobody looked :-(

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko