Re: boot2 overflow when building with clang

From: Peter Wemm <peter_at_wemm.org>
Date: Thu, 8 Mar 2012 10:43:28 -0800
On Wed, Mar 7, 2012 at 4:18 PM, Jung-uk Kim <jkim_at_freebsd.org> wrote:
> On Tuesday 06 March 2012 11:51 pm, Jia-Shiun Li wrote:
>> I am not familiar with boot2, but it looks like allocated size for
>> boot2 is not enough to hold code generated by clang. Reverting
>> r232570 fixes it.
>>
>> ===> sys/boot/i386/boot2 (all)
>> objcopy -S -O binary boot1.out boot1
>> dd if=/dev/zero of=boot2.ldr bs=512 count=1
>> clang -Os  -fno-guess-branch-probability  -fomit-frame-pointer
>> -fno-unit-at-a-time  -mno-align-long-strings  -mrtd  -mregparm=3
>> -DUSE_XREAD  -DUFS1_AND_UFS2  -DFLAGS=0x80  -DSIOPRT=0x3f8
>> -DSIOFMT=0x3  -DSIOSPD=9600
>> -I/usr/src/sys/boot/i386/boot2/../../common
>> -I/usr/src/sys/boot/i386/boot2/../btx/lib -I.  -Wall
>> -Waggregate-return -Wbad-function-cast -Wcast-align
>> -Wmissing-declarations -Wmissing-prototypes -Wnested-externs
>> -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
>> -Winline --param max-inline-insns-single=100  -mllvm
>> -stack-alignment=8 -mllvm -inline-threshold=3  -mllvm
>> -enable-load-pre=false -ffreestanding -mpreferred-stack-boundary=2
>> -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float
>> -std=gnu99    -S -o boot2.s.tmp
>> /usr/src/sys/boot/i386/boot2/boot2.c
>> sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
>> rm -f boot2.s.tmp
>> clang  -c boot2.s
>> clang -Os  -fno-guess-branch-probability  -fomit-frame-pointer
>> -fno-unit-at-a-time  -mno-align-long-strings  -mrtd  -mregparm=3
>> -DUSE_XREAD  -DUFS1_AND_UFS2  -DFLAGS=0x80  -DSIOPRT=0x3f8
>> -DSIOFMT=0x3  -DSIOSPD=9600
>> -I/usr/src/sys/boot/i386/boot2/../../common
>> -I/usr/src/sys/boot/i386/boot2/../btx/lib -I.  -Wall
>> -Waggregate-return -Wbad-function-cast -Wcast-align
>> -Wmissing-declarations -Wmissing-prototypes -Wnested-externs
>> -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
>> -Winline --param max-inline-insns-single=100  -mllvm
>> -stack-alignment=8 -mllvm -inline-threshold=3  -mllvm
>> -enable-load-pre=false -ffreestanding -mpreferred-stack-boundary=2
>> -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float
>> -std=gnu99     -c
>> /usr/src/sys/boot/i386/boot2/sio.S
>> ld -static -N --gc-sections -nostdlib -Ttext 0x2000 -o boot2.out
>> /usr/obj/usr/src/sys/boot/i386/boot2/../btx/lib/crt0.o boot2.o
>> sio.o objcopy -S -O binary boot2.out boot2.bin
>> btxld -v -E 0x2000 -f bin -b
>> /usr/obj/usr/src/sys/boot/i386/boot2/../btx/btx/btx -l boot2.ldr
>> -o boot2.ld -P 1 boot2.bin
>> kernel: ver=1.02 size=690 load=9000 entry=9010 map=16M pgctl=1:1
>> client: fmt=bin size=15a1 text=0 data=0 bss=0 entry=0
>> output: fmt=bin size=1e31 text=200 data=1c31 org=0 entry=0
>> -49 bytes available
>> *** [boot2] Error code 1
>>
>> Stop in /usr/src/sys/boot/i386/boot2.
>> *** [all] Error code 1
>>
>> Stop in /usr/src/sys/boot/i386.
>> *** [all] Error code 1
>>
>> Stop in /usr/src/sys/boot.
>> *** [all] Error code 1
>>
>> Stop in /usr/src/sys.
>> *** [sys.all__D] Error code 1
>>
>> Stop in /usr/src.
>> *** [everything] Error code 1
>>
>> Stop in /usr/src.
>> *** [buildworld] Error code 1
>>
>> Stop in /usr/src.
>
> Here is a patch to work around the problem:
>
> http://people.freebsd.org/~jkim/boot2.diff
>
> Please note this patch creates two separate boot codes, one for UFS1
> and one for UFS2.  To generate previous boot code (i.e., UFS1+UFS2)
> with GCC, clean objects, add the following line to
> your /etc/make.conf, rebuild, and install:
>
> BOOT2_UFS=UFS1_AND_UFS2

I think this should be committed.

If you're concerned about separating them, you can make this case
default for gcc.
There's glue in src/Makefile.inc1 that gives some hints about how this is done
.if ${MK_CLANG} != "no" && (${MK_CLANG_IS_CC} != "no" ||
${CC:T:Mclang} == "clang")

eg: if building with clang, default to UFS2, else UFS1_AND_UFS2

But please commit something.  Personally I think we could use the
spare space in boot2 in any case.

-- 
Peter Wemm - peter_at_wemm.org; peter_at_FreeBSD.org; peter_at_yahoo-inc.com; KI6FJV
"All of this is for nothing if we don't go to the stars" - JMS/B5
"If Java had true garbage collection, most programs would delete
themselves upon execution." -- Robert Sewell
Received on Thu Mar 08 2012 - 18:06:23 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:24 UTC