XCompiler

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

XCompiler

Post by brodeur235 »

All I need is binutils to run on my mac 10.6 snow leopard to complete builds of my OS. (the only tools I used on a linux machine were nasm and ld). I have nasm working, but binutils will not install. YES! I've read the cross compiler wiki article and following it's instructions or not, I get an error. Here's what I get:

Code: Select all

NICK-PACHULSKIs-MacBook:binutils-2.10.1 nmpach$ sudo ./configure --target=i386 --disable-n1s
Configuring for a i386 host.
Created "Makefile" in /usr/src/binutils-2.10.1
rm: conftest.dSYM: is a directory
Configuring intl...
loading cache ../config.cache
checking for a BSD compatible install... (cached) /usr/bin/install -c
checking how to run the C preprocessor... (cached) gcc -E
checking whether make sets ${MAKE}... (cached) yes
checking for gcc... (cached) gcc
checking whether the C compiler (gcc -g -O2 -W -Wall ) works... yes
checking whether the C compiler (gcc -g -O2 -W -Wall ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for ranlib... (cached) ranlib
checking for POSIXized ISC... no
checking for ANSI C header files... (cached) yes
checking for working const... (cached) yes
checking for inline... (cached) inline
checking for off_t... (cached) yes
checking for size_t... (cached) yes
checking for working alloca.h... (cached) yes
checking for alloca... (cached) yes
checking for unistd.h... (cached) yes
checking for getpagesize... (cached) yes
checking for working mmap... (cached) yes
checking for argz.h... (cached) no
checking for limits.h... (cached) yes
checking for locale.h... (cached) yes
checking for nl_types.h... (cached) yes
checking for malloc.h... (cached) no
checking for string.h... (cached) yes
checking for unistd.h... (cached) yes
checking for values.h... (cached) no
checking for sys/param.h... (cached) yes
checking for getcwd... (cached) yes
checking for munmap... (cached) yes
checking for putenv... (cached) yes
checking for setenv... (cached) yes
checking for setlocale... (cached) yes
checking for strchr... (cached) yes
checking for strcasecmp... (cached) yes
checking for __argz_count... (cached) no
checking for __argz_stringify... (cached) no
checking for __argz_next... (cached) no
checking for LC_MESSAGES... (cached) yes
checking whether NLS is requested... yes
checking whether included gettext is requested... no
checking for libintl.h... (cached) no
checking for msgfmt... (cached) msgfmt
checking for gmsgfmt... (cached) msgfmt
checking for xgettext... (cached) :
creating ./config.status
creating Makefile
creating config.h
config.h is unchanged
linking ./libgettext.h to libintl.h
Configuring libiberty...
loading cache ../config.cache
checking host system type... i386-pc-none
checking build system type... i386-pc-none
checking for ar... (cached) ar
checking for ranlib... (cached) ranlib
checking for gcc... (cached) gcc
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for POSIXized ISC... no
checking for a BSD compatible install... (cached) /usr/bin/install -c
xhost-mkfrag is unchanged
checking how to run the C preprocessor... (cached) gcc -E
checking for sys/file.h... (cached) yes
checking for sys/param.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for unistd.h... (cached) yes
checking for strings.h... (cached) yes
checking for sys/time.h... (cached) yes
checking for sys/resource.h... (cached) yes
checking for sys/stat.h... (cached) yes
checking for sys/wait.h that is POSIX.1 compatible... (cached) yes
checking whether the C compiler (gcc -g -O2 -W -Wall ) works... yes
checking whether the C compiler (gcc -g -O2 -W -Wall ) is a cross-compiler... no
checking for asprintf... (cached) yes
checking for atexit... (cached) yes
checking for basename... (cached) yes
checking for bcmp... (cached) yes
checking for bcopy... (cached) yes
checking for bzero... (cached) yes
checking for calloc... (cached) yes
checking for clock... (cached) yes
checking for getcwd... (cached) yes
checking for getpagesize... (cached) yes
checking for index... (cached) yes
checking for insque... (cached) yes
checking for memchr... (cached) yes
checking for memcmp... (cached) yes
checking for memcpy... (cached) yes
checking for memmove... (cached) yes
checking for memset... (cached) yes
checking for mkstemps... (cached) yes
checking for putenv... (cached) yes
checking for random... (cached) yes
checking for rename... (cached) yes
checking for rindex... (cached) yes
checking for setenv... (cached) yes
checking for sigsetmask... (cached) yes
checking for strcasecmp... (cached) yes
checking for strchr... (cached) yes
checking for strdup... (cached) yes
checking for strncasecmp... (cached) yes
checking for strrchr... (cached) yes
checking for strstr... (cached) yes
checking for strtod... (cached) yes
checking for strtol... (cached) yes
checking for strtoul... (cached) yes
checking for tmpnam... (cached) yes
checking for vasprintf... (cached) yes
checking for vfprintf... (cached) yes
checking for vprintf... (cached) yes
checking for vsprintf... (cached) yes
checking for waitpid... (cached) yes
checking for working alloca.h... (cached) yes
checking for alloca... (cached) yes
checking for ANSI C header files... (cached) yes
checking for pid_t... (cached) yes
checking for vfork.h... (cached) no
checking for working vfork... (cached) yes
checking for sys_errlist... (cached) yes
checking for sys_nerr... (cached) yes
checking for sys_siglist... (cached) yes
checking for getrusage... (cached) yes
checking for on_exit... (cached) no
checking for psignal... (cached) yes
checking for strerror... (cached) yes
checking for strsignal... (cached) yes
checking for sysconf... (cached) yes
checking for times... (cached) yes
checking for sbrk... (cached) yes
checking for gettimeofday... (cached) yes
creating ./config.status
creating Makefile
creating testsuite/Makefile
creating config.h
config.h is unchanged
Configuring opcodes...
loading cache ../config.cache
checking host system type... i386-pc-none
checking target system type... i386-pc-none
checking build system type... i386-pc-none
checking for gcc... (cached) gcc
checking whether the C compiler (gcc -g -O2 -W -Wall ) works... yes
checking whether the C compiler (gcc -g -O2 -W -Wall ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for POSIXized ISC... no
checking for a BSD compatible install... (cached) /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... (cached) yes
checking for working aclocal... found
checking for working autoconf... found
checking for working automake... found
checking for working autoheader... found
checking for working makeinfo... found
checking for ar... (cached) ar
checking for ranlib... (cached) ranlib
checking for ranlib... (cached) ranlib
checking for ld used by GCC... (cached) /usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld
checking if the linker (/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld) is GNU ld... (cached) no
checking for BSD-compatible nm... (cached) /usr/bin/nm
checking whether ln -s works... (cached) yes
loading cache ../config.cache within ltconfig
checking for object suffix... o
checking for executable suffix... (cached) .dSYM
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.lo... yes
checking if gcc supports -fno-rtti -fno-exceptions ... no
checking if gcc static flag -static works... none
checking if the linker (/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld) is GNU ld... no
checking whether the linker (/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld) supports shared libraries... no
checking command to parse /usr/bin/nm output... rm: conftest.dSYM: is a directory
ok
checking how to hardcode library paths into programs... unsupported
checking for /usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld option to reload object files... -r
checking dynamic linker characteristics... no
checking if libtool supports shared libraries... no
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking for objdir... .libs
creating libtool
loading cache ../config.cache
checking whether to enable maintainer-specific portions of Makefiles... no
checking for Cygwin environment... no
checking for mingw32 environment... no
checking for executable suffix... (cached) .dSYM
checking for gcc... (cached) gcc
checking whether the C compiler (gcc -g -O2 -W -Wall ) works... yes
checking whether the C compiler (gcc -g -O2 -W -Wall ) is a cross-compiler... yes
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking how to run the C preprocessor... (cached) gcc -E
checking for ANSI C header files... (cached) yes
checking for working const... (cached) yes
checking for inline... (cached) inline
checking for off_t... (cached) yes
checking for size_t... (cached) yes
checking for working alloca.h... (cached) yes
checking for alloca... (cached) yes
checking for unistd.h... (cached) yes
checking for getpagesize... (cached) yes
checking for working mmap... (cached) yes
checking for argz.h... (cached) no
checking for limits.h... (cached) yes
checking for locale.h... (cached) yes
checking for nl_types.h... (cached) yes
checking for malloc.h... (cached) no
checking for string.h... (cached) yes
checking for unistd.h... (cached) yes
checking for values.h... (cached) no
checking for sys/param.h... (cached) yes
checking for getcwd... (cached) yes
checking for munmap... (cached) yes
checking for putenv... (cached) yes
checking for setenv... (cached) yes
checking for setlocale... (cached) yes
checking for strchr... (cached) yes
checking for strcasecmp... (cached) yes
checking for __argz_count... (cached) no
checking for __argz_stringify... (cached) no
checking for __argz_next... (cached) no
checking for LC_MESSAGES... (cached) yes
checking whether NLS is requested... yes
checking whether included gettext is requested... no
checking for libintl.h... (cached) no
checking for msgfmt... (cached) msgfmt
checking for gmsgfmt... (cached) msgfmt
checking for xgettext... (cached) :
checking for a BSD compatible install... /usr/bin/install -c
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking for stdlib.h... (cached) yes
*** BFD does not support target i386-pc-none.
*** Look in bfd/config.bfd for supported targets.
Configure in /usr/src/binutils-2.10.1/opcodes failed, exiting.
Help appreciated,

Brodeur235
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: XCompiler

Post by Combuster »

No, you did not follow the instructions. Read the tutorial again and follow it to the letter.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: XCompiler

Post by Creature »

I think this might be a tip to help you:

Code: Select all

i386-pc-none
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

Re: XCompiler

Post by brodeur235 »

I've now set up the dir tree exactly how the tutorial specifies and with the same environment vars. Configuration ends with this error:

Code: Select all

configure: error: installation or configuration problem: C compiler cannot create executables.
Configure in /usr/src/build-binutils/bfd failed, exiting.
I used i586-elf and installed to the correct dir /usr/cross. Help appreciated,

Brodeur235
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: XCompiler

Post by Combuster »

binutils-2.10.1
Did you fix that yet?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: XCompiler

Post by Brynet-Inc »

Yet another person fails to read dates, here's a hint.. 2.10.1 was released in what year?
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

Re: XCompiler

Post by brodeur235 »

Thank you both. I got it installed. Also, a note for anyone else trying to install binutils on mac 10.6 Snow Leopard, when you configure binutils you have to add the -disable-werror option in addition to the others. Otherwise, 5 warnings result as errors stopping the make.

I do have another problem however, that has been asked about a hundred times, yet I can't understand the problem still. Sorry for being so difficult; I'm probably really frustrating and for that I apologize. Anyways, I've got my OS that I coded over the summer on ubuntu and it compiled, linked, and ran fine then. Now, there is a problem I've never seen before. There are about 30 modules to the OS so I'll only include the ones that pertain...

Here's my build script:

Code: Select all

echo 
echo Now Assembling Your Operating System . . .

nasm ./../sources/"boot loader"/"boot loader.asm" -f elf -o ./../sources/"boot loader"/"boot loader.o" -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_main/k_main.asm -f elf -o ./../sources/kernel/k_main/k_main.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_screen/k_screen.asm -f elf -o ./../sources/kernel/k_screen/k_screen.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_cpuid/k_cpuid.asm -f elf -o ./../sources/kernel/k_cpuid/k_cpuid.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_irq/k_irq.asm -f elf -o ./../sources/kernel/k_irq/k_irq.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_idt_procs/k_idt_procs.asm -f elf -o ./../sources/kernel/k_idt_procs/k_idt_procs.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_idt_table/k_idt_table.asm -f elf -o ./../sources/kernel/k_idt_table/k_idt_table.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_isr/k_isr.asm -f elf -o ./../sources/kernel/k_isr/k_isr.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_mem_utils/k_mem_utils.asm -f elf -o ./../sources/kernel/k_mem_utils/k_mem_utils.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/k_conversions/k_conversions.asm -f elf -o ./../sources/kernel/k_conversions/k_conversions.o -i /Users/nmpach/"Synergy OS"/sources/headers/
nasm ./../sources/kernel/kbd_drvrs/us.asm -f elf -o ./../sources/kernel/kbd_drvrs/us.o -i /Users/nmpach/"Synergy OS"/sources/headers/

echo Completed.

echo 
echo Now Linking Your Operating System . . .

/usr/src/build-binutils/ld/ld-new \
-e bl_main \
--oformat binary \
./../sources/"boot loader"/"boot loader.o" \
./../sources/kernel/k_main/k_main.o \
./../sources/kernel/k_screen/k_screen.o \
./../sources/kernel/k_cpuid/k_cpuid.o \
./../sources/kernel/k_irq/k_irq.o \
./../sources/kernel/k_idt_procs/k_idt_procs.o \
./../sources/kernel/k_idt_table/k_idt_table.o \
./../sources/kernel/k_mem_utils/k_mem_utils.o \
./../sources/kernel/k_conversions/k_conversions.o \
./../sources/kernel/k_isr/k_isr.o \
./../sources/kernel/kbd_drvrs/us.o

echo Completed.

echo 
echo Build Complete.
echo 
Here's the output from the build script:

Code: Select all

NICK-PACHULSKIs-MacBook:build tools nmpach$ ./build.sh

Now Assembling Your Operating System . . .
Completed.

Now Linking Your Operating System . . .
./../sources/boot loader/boot loader.o: In function `bl_main':
./../sources/boot loader/boot loader.asm:(.text+0x15): relocation truncated to fit: R_386_16 against `.text'
./../sources/boot loader/boot loader.o: In function `kernel_loader':
./../sources/boot loader/boot loader.asm:(.text+0x40): relocation truncated to fit: R_386_16 against `.text'
./../sources/boot loader/boot loader.asm:(.text+0x46): relocation truncated to fit: R_386_16 against `.text'
./../sources/boot loader/boot loader.o: In function `kernel_loader.kl_copy_sector':
./../sources/boot loader/boot loader.asm:(.text+0x55): relocation truncated to fit: R_386_16 against `.text'
./../sources/boot loader/boot loader.asm:(.text+0x59): relocation truncated to fit: R_386_16 against `.text'
./../sources/boot loader/boot loader.asm:(.text+0x64): relocation truncated to fit: R_386_16 against `.text'
./../sources/boot loader/boot loader.asm:(.text+0x6f): relocation truncated to fit: R_386_16 against `.text'
./../sources/boot loader/boot loader.asm:(.text+0x77): relocation truncated to fit: R_386_16 against `.text'
Completed.

Build Complete.
Here's the bootloader module which seems to be causing all the trouble:

Code: Select all

;||=====================================================||
;||                      BOOT LOADER                    ||
;||=====================================================||
%define BL_LOADER
%include "system.inc"

[BITS 16]

global bl_main
bl_main:
	
	; disable interrupts
	cli
	
	; setup stack
	xor ax,ax
	mov ss,ax
	mov esp,0x00007C00
	
	; setup data
	xor ax,ax
	mov ds,ax
	
	; load kernel
	call kernel_loader
	
	; load gdt
	lgdt [ BLOC( gdt_descriptor ) ]
	
	; enter pmode
	mov eax,cr0
	or eax,1
	mov cr0,eax
	
	; jmp to protected mode
	jmp DWORD 0x08:KERNEL_OFFSET

kernel_loader:
	
	; determine # of sectors to load
	; dx:ax / bx = ax remainder dx
	mov dx,0x0000
	mov ax,KERNEL_SIZE
	mov bx,SECTOR_SIZE
	div bx
	
	; ensure size is even number of sectors
	cmp dx,0x0000
	jnz .kl_error
	
	; setup to loop thru sectors
	mov cx,ax
	mov BYTE [ BLOC( sector_current ) ], KERNEL_SECTOR
	mov DWORD [ BLOC( offset_current ) ], KERNEL_OFFSET
	.kl_copy_sector:
		push cx
		
		; copy current sector
		; disk loc -> es:bx in mem
		mov dh,KERNEL_DRIVE
		mov dl,KERNEL_HEAD
		mov ch,KERNEL_TRACK
		mov cl,[ BLOC( sector_current ) ]
		
		; setup destination ( es:bx)
		mov eax,DWORD [ BLOC( offset_current ) ]
		shr eax,0x00000010
		mov es,ax
		mov ebx,DWORD [ BLOC( offset_current ) ]
		
		mov ah,0x02
		mov al,0x01
		int 0x13
		
		; prepare for next sector
		add DWORD [ BLOC( offset_current ) ],SECTOR_SIZE
		inc BYTE [ BLOC( sector_current ) ]
		
		pop cx
		loop .kl_copy_sector
	
	; completed
	jmp .kl_success
	
	; error section
	.kl_error:
		jmp $
	
	; success section
	.kl_success:
		ret

gdt_entries:
	
	; null entry
	db 00000000b
	db 00000000b
	db 00000000b
	db 00000000b
	db 00000000b
	db 00000000b
	db 00000000b
	db 00000000b
	
	; code segment descriptor: OFFSET = 0x0008
	db 11111111b
	db 11111111b
	db 00000000b
	db 00000000b
	db 00000000b
	db 10011010b
	db 11001111b
	db 00000000b
	
	; data segment descriptor: OFFSET = 0x0010
	db 11111111b
	db 11111111b
	db 00000000b
	db 00000000b
	db 00000000b
	db 10010010b
	db 11001111b
	db 00000000b
	
gdt_descriptor:
	
	; table size (2 bytes)
	dw (gdt_descriptor - gdt_entries - 1)
	
	; table offset (4 bytes)
	dd (gdt_entries+0x7C00)
	
bl_data:
	
	; kernel_load data
	sector_current db 0x00 ; KERNEL_SECTOR
	offset_current dd 0x00000000 ; KERNEL_OFFSET
	
bl_padding:
	
	;pad to 510 bytes
	times (512-2-($-bl_main)) db 0x00
	
	;make disk bootable w/ 2 byte flag
	db 0x55
	db 0xAA

;||=====================================================||
;||                    END BOOT LOADER                  ||
;||=====================================================||
Most people who had this same error were switching in and out of protected and real mode. All I do is switch to protected once and jump to my kernel. I don't understand why this doesn't work all of a sudden because it did in Ubuntu...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: XCompiler

Post by Combuster »

At least your building pipeline is broken - you are assuming that your linker puts everything starting from address 0, which is not the case. I would expect it to break in ubuntu too.

Also, a bug (not a feature IMNSHO) in ld makes that the relocation truncations become warnings, not errors like they should be. Your binary is corrupt, end of story.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply