Help needed cleaning up sys/boot/{efi,ia64}/ makefiles

Ruslan Ermilov ru at FreeBSD.org
Wed Feb 11 06:24:57 PST 2004


Gang,

As you've probably noticed, I've been working towards cleaning up
sys/boot/ makefiles for some time already, and now is the time for
IA64.

I've compile-tested the attached patch on pluto2 today.  I tested
my changes by binary comparing the resulting binaries, in the same
way as I did it for other architectures (i386, amd64 and sparc64).

One thing about IA64 surprises me, and I hope you can help me here.
With my patch, I get a slightly different "loader.sym" binary, and
this is due to linking, i.e., all intermediate objects are the same.
I first took away the -M option to ld(1) to not generate the link
map.  An analysis shown that this was responsible for a difference.
I've put it back, and (as could be seen by adding -v to LDFLAGS
after applying the patch), the link command now looks like this:

: ld -Bshareable -Bsymbolic -o loader.sym \
: -L/usr/lib \
: -T/q/scratch/ru/src/sys/boot/efi/loader/../libefi/arch/ia64/ldscript.ia64 \
: -M -Map loader.list \
: start.o main.o conf.o dev_net.o bcache.o boot.o commands.o console.o \
: devopen.o interp.o interp_backslash.o interp_parse.o ls.o misc.o module.o \
: panic.o load_elf64.o interp_forth.o vers.o \
: /q/scratch/ru/obj/q/scratch/ru/src/sys/boot/efi/loader/../../ficl/libficl.a \
: /q/scratch/ru/obj/q/scratch/ru/src/sys/boot/efi/loader/../libefi/libefi.a \
: -lstand

But this still gives a difference.  By disassembling the resulting
binary, I see the constant difference of 40 bytes in various offset,
if I'm guessing the IA64 asm code correctly.  Then the constant
changes.  The elfdump(1) also shows the difference in relocations.

But if I change to an object directory, and relink loader.sym manually
by tweaking the link command a bit (by changing -L/usr/lib to -nostdlib
and replacing -lstand with /usr/lib/libstand.a), I see no difference
(except probably for "normal" difference influenced by regenerating
vers.c, if I regenerate it).

;   ld -Bshareable -Bsymbolic -o loader.sym \
; - -L/usr/lib \
; + -nostdlib \
;   -T/q/scratch/ru/src/sys/boot/efi/loader/../libefi/arch/ia64/ldscript.ia64 \
;   -M -Map loader.list \
;   start.o main.o conf.o dev_net.o bcache.o boot.o commands.o console.o \
;   devopen.o interp.o interp_backslash.o interp_parse.o ls.o misc.o module.o \
;   panic.o load_elf64.o interp_forth.o vers.o \
;   /q/scratch/ru/obj/q/scratch/ru/src/sys/boot/efi/loader/../../ficl/libficl.a \
;   /q/scratch/ru/obj/q/scratch/ru/src/sys/boot/efi/loader/../libefi/libefi.a \
; - -lstand
; + /usr/lib/libstand.a

So I have a few questions:

- Why the hell removing -M from linker flags (both in unpatched and
  patched versions of makefiles) seems to affect the loader.sym binary?

- Is it safe to commit my patch?  Can someone please run-test it?

- Is there a reason why libski is built with -g?  Is it safe to
  remove it?

- What is the reason that we cannot strip the skiload binary?  (A
  slightly more verbose explanation than the below would be nice.)

: revision 1.12
: date: 2003/11/09 06:53:37;  author: marcel;  state: Exp;  lines: +1 -0
: Do not strip skiload when installed. The stripped binary does not load
: in the simulator.

- What is the reason that we cannot strip the boot.efi binary?  (A
  slightly more verbose explanation than the below would be nice.)

: revision 1.17
: date: 2002/04/07 04:27:50;  author: peter;  state: Exp;  lines: +1 -0
: We must not let install(1) strip loader.efi when installing it, or the
: resulting binary will be damaged and no longer work.


Cheers,
-- 
Ruslan Ermilov
FreeBSD committer
ru at FreeBSD.org
-------------- next part --------------
Index: efi/Makefile.inc
===================================================================
RCS file: /home/ncvs/src/sys/boot/efi/Makefile.inc,v
retrieving revision 1.6
diff -u -r1.6 Makefile.inc
--- efi/Makefile.inc	10 Dec 2002 04:20:15 -0000	1.6
+++ efi/Makefile.inc	11 Feb 2004 08:59:03 -0000
@@ -1,4 +1,7 @@
 # $FreeBSD: src/sys/boot/efi/Makefile.inc,v 1.6 2002/12/10 04:20:15 marcel Exp $
 
+BINDIR?=	/boot
+
 # Options used when building app-specific efi components
 CFLAGS+=	-ffreestanding -fshort-wchar -Wformat
+LDFLAGS+=	-nostdlib
Index: efi/libefi/Makefile
===================================================================
RCS file: /home/ncvs/src/sys/boot/efi/libefi/Makefile,v
retrieving revision 1.12
diff -u -r1.12 Makefile
--- efi/libefi/Makefile	2 Jul 2003 11:53:55 -0000	1.12
+++ efi/libefi/Makefile	9 Feb 2004 16:14:21 -0000
@@ -12,28 +12,21 @@
 SRCS+=	efifpswa.c
 .endif
 
-CFLAGS+=	-ffreestanding -fpic
+CFLAGS+=	-fpic
 CFLAGS+=	-I${.CURDIR}/../include
 CFLAGS+=	-I${.CURDIR}/../include/${MACHINE_ARCH}
-CFLAGS+=	-I${.CURDIR}/../../../../lib/libstand/
+CFLAGS+=	-I${.CURDIR}/../../../../lib/libstand
 
 # Pick up the bootstrap header for some interface items
-CFLAGS+=	-I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I.
+CFLAGS+=	-I${.CURDIR}/../../common
 
 .if ${MACHINE_ARCH} == "powerpc"
 CFLAGS+=	-msoft-float
 .endif
 
-.ifdef(BOOT_DISK_DEBUG)
+.if defined(BOOT_DISK_DEBUG)
 # Make the disk code more talkative
 CFLAGS+= -DDISK_DEBUG
 .endif
 
-machine:
-	ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine
-
-CLEANFILES+=	machine
-
 .include <bsd.lib.mk>
-
-beforedepend ${OBJS}: machine
Index: efi/loader/Makefile
===================================================================
RCS file: /home/ncvs/src/sys/boot/efi/loader/Makefile,v
retrieving revision 1.19
diff -u -r1.19 Makefile
--- efi/loader/Makefile	26 Feb 2003 06:18:52 -0000	1.19
+++ efi/loader/Makefile	11 Feb 2004 12:45:07 -0000
@@ -1,76 +1,45 @@
 # $FreeBSD: src/sys/boot/efi/loader/Makefile,v 1.19 2003/02/26 06:18:52 obrien Exp $
 
-.PATH: ${.CURDIR}/../common
-
-BASE= 		loader
-PROG= 		${BASE}.efi
+PROG= 		loader.sym
+INTERNALPROG=
 NOMAN=
 NEWVERSWHAT=	"EFI boot" ${MACHINE_ARCH}
-BINDIR?=	/boot
-STRIP=		# We must not strip loader.efi at install time.
 
-SRCS+=		main.c conf.c dev_net.c
+SRCS=		start.S main.c conf.c dev_net.c #vers.c
 
-CFLAGS+=	-ffreestanding
+.PATH: ${.CURDIR}/../libefi/arch/${MACHINE_ARCH}
 
 .if !defined(NOFORTH)
 # Enable BootForth
 BOOT_FORTH=	yes
 CFLAGS+=	-DBOOT_FORTH
 CFLAGS+=	-I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/${MACHINE_ARCH}
-.if exists(${.OBJDIR}/../../ficl/libficl.a)
 LIBFICL=	${.OBJDIR}/../../ficl/libficl.a
-.else
-LIBFICL=	${.CURDIR}/../../ficl/libficl.a
-.endif
-.endif
-
-# where to get libstand from
-.if exists(${.OBJDIR}/../../../../lib/libstand/libstand.a)
-LIBSTAND=	${.OBJDIR}/../../../../lib/libstand/libstand.a
-.else
-LIBSTAND=	${.CURDIR}/../../../../lib/libstand/libstand.a
 .endif
 
-.if exists(${.OBJDIR}/../libefi/libefi.a)
 LIBEFI=		${.OBJDIR}/../libefi/libefi.a
-.else
-LIBEFI=		${.CURDIR}/../libefi/libefi.a
-.endif
 
 # Always add MI sources 
 .PATH: ${.CURDIR}/../../common
-.include <${.CURDIR}/../../common/Makefile.inc>
+.include "${.CURDIR}/../../common/Makefile.inc"
 
-CFLAGS+= -I-
 CFLAGS+= -I${.CURDIR}/../include
 CFLAGS+= -I${.CURDIR}/../include/${MACHINE_ARCH}
-CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}
-CFLAGS+= -I${.CURDIR}/../../.. -I.
+CFLAGS+= -I${.CURDIR}/../../common
 CFLAGS+= -I${.CURDIR}/../libefi
 CFLAGS+= -I${.CURDIR}/../../../../lib/libstand
 CFLAGS+= -DLOADER
 
 LDSCRIPT=	${.CURDIR}/../libefi/arch/${MACHINE_ARCH}/ldscript.${MACHINE_ARCH}
-LDFLAGS=	-nostdlib -T ${LDSCRIPT} -shared -Bsymbolic
+LDFLAGS=	-Wl,-T${LDSCRIPT} -Wl,-M,-Map,loader.list -shared -symbolic
 OBJCOPY?=	objcopy
 
-CLEANFILES+=	setdef0.c setdef0.o setdef1.c setdef1.o setdefs.h start.o \
-		vers.c vers.o ${BASE}.efi ${BASE}.sym ${BASE}.list
-CLEANFILES+=	loader.help
-CLEANFILES+=	machine
-
-CRT=	start.o
-
-all: ${BASE}
+CLEANFILES=	vers.c loader.efi loader.list loader.help
 
-vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
+vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
 	sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
-	${CC} -c vers.c
 
-${BASE}:	${BASE}.efi ${BASE}.help
-
-${BASE}.efi: ${BASE}.sym
+loader.efi: loader.sym
 	${OBJCOPY} -j .text \
 		-j .hash \
 		-j .data \
@@ -81,43 +50,24 @@
 		-j .dynsym \
 		-j .dynstr \
 		--target=efi-app-${MACHINE_ARCH} \
-		${BASE}.sym ${BASE}.efi
+		loader.sym loader.efi
 
-${BASE}.help:	help.common
+loader.help:	help.common
 	cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk \
 	    > ${.TARGET}
 
-beforeinstall:
-.if exists(${.OBJDIR}/loader.help)
-	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
-		${.OBJDIR}/${BASE}.help ${DESTDIR}/boot
-.else
-	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
-		${.CURDIR}/${BASE}.help ${DESTDIR}/boot
-.endif
+.PATH: ${.CURDIR}/../../forth
+FILES=	loader.efi loader.help loader.4th support.4th loader.conf
+FILESMODE_loader.efi= ${BINMODE}
+FILESDIR_loader.conf=	/boot/defaults
+
 .if !exists(${DESTDIR}/boot/loader.rc)
-	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
-		${.CURDIR}/../../forth/loader.rc ${DESTDIR}/boot
+FILES+=	${.CURDIR}/loader.rc
 .endif
-	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
-		${.CURDIR}/../../forth/loader.4th ${DESTDIR}/boot
-	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
-		${.CURDIR}/../../forth/support.4th ${DESTDIR}/boot
-	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
-		${.CURDIR}/../../forth/loader.conf ${DESTDIR}/boot/defaults
 
+SRCS+=	vers.c
 
-# Other fragments still to be brought in from ../Makfile.booters?
-start.o: ${.CURDIR}/../libefi/arch/${MACHINE_ARCH}/start.S
-	${CC} -c ${CFLAGS} ${.IMPSRC}
-
-machine:
-	ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine
+DPADD=	${LIBFICL} ${LIBEFI} ${LIBSTAND}
+LDADD=	${LIBFICL} ${LIBEFI} -lstand
 
 .include <bsd.prog.mk>
-
-${BASE}.sym: ${OBJS} ${LIBFICL} ${LIBEFI} ${LIBSTAND} ${CRT} vers.o
-	${LD} ${LDFLAGS} -o ${BASE}.sym -M ${CRT} ${OBJS} vers.o \
-	    ${LIBFICL} ${LIBEFI} ${LIBSTAND} > ${.OBJDIR}/${BASE}.list
-
-beforedepend ${OBJS}: machine
Index: ia64/Makefile.inc
===================================================================
RCS file: /home/ncvs/src/sys/boot/ia64/Makefile.inc,v
retrieving revision 1.2
diff -u -r1.2 Makefile.inc
--- ia64/Makefile.inc	1 Feb 2003 22:50:08 -0000	1.2
+++ ia64/Makefile.inc	11 Feb 2004 13:02:05 -0000
@@ -1,4 +1,7 @@
 # $FreeBSD: src/sys/boot/ia64/Makefile.inc,v 1.2 2003/02/01 22:50:08 marcel Exp $
 
+BINDIR?=	/boot
+
 # Options used when building standalone components
 CFLAGS+=	-ffreestanding -fshort-wchar -Wformat
+LDFLAGS+=	-nostdlib
Index: ia64/libski/Makefile
===================================================================
RCS file: /home/ncvs/src/sys/boot/ia64/libski/Makefile,v
retrieving revision 1.10
diff -u -r1.10 Makefile
--- ia64/libski/Makefile	2 Jul 2003 11:47:33 -0000	1.10
+++ ia64/libski/Makefile	11 Feb 2004 13:36:11 -0000
@@ -7,30 +7,21 @@
 SRCS+=	delay.c skifs.c elf_freebsd.c bootinfo.c ssc.c
 SRCS+=	acpi_stub.c efi_stub.c pal_stub.S sal_stub.c
 
-CFLAGS+=	-ffreestanding -fpic -g
-CFLAGS+=	-I${.CURDIR}/../include
-CFLAGS+=	-I${.CURDIR}/../include/${MACHINE_ARCH}
-CFLAGS+=	-I${.CURDIR}/../../../../lib/libstand/
+CFLAGS+=	-fpic -g
+CFLAGS+=	-I${.CURDIR}/../../../../lib/libstand
 CFLAGS+=	-I${.CURDIR}/../../efi/include
 CFLAGS+=	-I${.CURDIR}/../../efi/include/${MACHINE_ARCH}
 
 # Pick up the bootstrap header for some interface items
-CFLAGS+=	-I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I.
+CFLAGS+=	-I${.CURDIR}/../../common -I${.CURDIR}/../../..
 
 .if ${MACHINE_ARCH} == "powerpc"
 CFLAGS+=	-msoft-float
 .endif
 
-.ifdef(BOOT_DISK_DEBUG)
+.if defined(BOOT_DISK_DEBUG)
 # Make the disk code more talkative
 CFLAGS+= -DDISK_DEBUG
 .endif
 
-machine:
-	ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine
-
-CLEANFILES+=	machine
-
 .include <bsd.lib.mk>
-
-beforedepend ${OBJS}: machine
Index: ia64/skiload/Makefile
===================================================================
RCS file: /home/ncvs/src/sys/boot/ia64/skiload/Makefile,v
retrieving revision 1.12
diff -u -r1.12 Makefile
--- ia64/skiload/Makefile	9 Nov 2003 06:53:37 -0000	1.12
+++ ia64/skiload/Makefile	11 Feb 2004 13:14:24 -0000
@@ -8,78 +8,40 @@
 BINDIR?=	/boot
 STRIP=		# We must not strip skiload at install time.
 
-SRCS+=		conf.c main.c start.S
-
-CFLAGS+=	-ffreestanding
+SRCS=		conf.c main.c start.S vers.c
 
 .if !defined(NOFORTH)
 # Enable BootForth
 BOOT_FORTH=	yes
 CFLAGS+=	-DBOOT_FORTH
 CFLAGS+=	-I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/${MACHINE_ARCH}
-.if exists(${.OBJDIR}/../../ficl/libficl.a)
 LIBFICL=	${.OBJDIR}/../../ficl/libficl.a
-.else
-LIBFICL=	${.CURDIR}/../../ficl/libficl.a
-.endif
 .endif
 
-# where to get libstand from
-.if exists(${.OBJDIR}/../../../../lib/libstand/libstand.a)
-LIBSTAND=       ${.OBJDIR}/../../../../lib/libstand/libstand.a
-.else
-LIBSTAND=       ${.CURDIR}/../../../../lib/libstand/libstand.a
-.endif
-
-.if exists(${.OBJDIR}/../libski/libski.a)
 LIBSKI=		${.OBJDIR}/../libski/libski.a
-.else
-LIBSKI=		${.CURDIR}/../libski/libski.a
-.endif
 
 # Always add MI sources 
 .PATH: ${.CURDIR}/../../common
-.include <${.CURDIR}/../../common/Makefile.inc>
+.include "${.CURDIR}/../../common/Makefile.inc"
 
-CFLAGS+= -I-
-CFLAGS+= -I${.CURDIR}/../include
-CFLAGS+= -I${.CURDIR}/../include/${MACHINE_ARCH}
-CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}
-CFLAGS+= -I${.CURDIR}/../../.. -I.
+CFLAGS+= -I${.CURDIR}/../../common
 CFLAGS+= -I${.CURDIR}/../libski
 CFLAGS+= -DLOADER
 
-LDFLAGS=	-nostdlib -T ${.CURDIR}/ldscript.ia64
+LDFLAGS=	-Wl,-T${.CURDIR}/ldscript.ia64 -Wl,-M,-Map,${PROG}.list
 
-CLEANFILES+=	vers.c vers.o ${PROG}.list
-CLEANFILES+=	loader.help
-CLEANFILES+=	machine
+CLEANFILES=	vers.c ${PROG}.list ${PROG}.help
 
-all: ${PROG}
-
-vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
+vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
 	sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
-	${CC} -c vers.c
 
-${PROG}.help:	help.common help.efi
+${PROG}.help: help.common
 	cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk \
 	    > ${.TARGET}
 
-beforeinstall:
-.if exists(${.OBJDIR}/${PROG}.help)
-	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
-	    ${.OBJDIR}/${PROG}.help ${DESTDIR}/boot
-.endif
-
-machine:
-	ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine
+FILES=	${PROG}.help
 
-${PROG}: ${OBJS} ${LIBFICL} ${LIBSKI} ${LIBSTAND} vers.o
-	${LD} ${LDFLAGS} -o ${PROG} -M \
-	    ${OBJS} vers.o \
-	    ${LIBFICL} ${LIBSTAND} ${LIBSKI} ${LIBSTAND} \
-	    > ${.OBJDIR}/${PROG}.list
+DPADD=	${LIBFICL} ${LIBSKI} ${LIBSTAND}
+LDADD=	${LIBFICL} ${LIBSKI} -lstand
 
 .include <bsd.prog.mk>
-
-beforedepend ${OBJS}: machine
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-ia64/attachments/20040211/6f54a3b3/attachment.bin


More information about the freebsd-ia64 mailing list