Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Help With Kernel Linker Script

c assembly linker

Best Answer Alexander, 24 September 2014 - 04:27 AM

You are correct about formatting being the issue, but in the wrong place. Whatever encoding you are using for a single dash "-" is three bytes, and your terminal does not like it. Were you copying the example from somewhere that misencoded the character? Try to replace them with your own dashes to see if this resolves the issue.

 

As a programmer, try to look at the error as a stack, and dig backwards until you find the root cause of it:

ld ���T link.ld ���o kernel.bin main.o boot.o
ld
: cannot find ���T: No such file or directory
link
.ld: file not recognized: File format not recognized

 

This is not your linker putting out something misformatted, it appears to be reporting it is looking for a file named ???T and you must investigate it.

 

Why is T important? And what is the filename after it?

 

Look at the man page for ld: http://linux.die.net/man/1/ld

 

You can see that ld can use linker scripts with the switch -T, and the dash is clearly missing from the output, and therefor the dash must be the offending character (converted in to three bytes when put in an eight bit-per-character environment such as the common console)

 

Alexander.

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1 Poe

Poe

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 81 posts

Posted 23 September 2014 - 08:09 PM

ENTRY(start)
phys = 0x00100000;
SECTIONS 
{
	.text phys : AT(phys) {
		code = .;
		*(.text)
		∗(.rodata)
		. = ALIGN(4096);   
    }

	.data : AT(phys + (data − code)) {
		data = .;
		∗(.data)
		. = ALIGN(4096);
	}

	.bss : AT(phys + (bss − code)) {
		bss = .;
		∗(.bss)
		. = ALIGN(4096);
	}
	end =  .;

}

This linker script is giving me a make error.  My assembler and C compile fine (well C gives a warning but thats because it does nothing yet)

 

Heres the error (is is just bad formatting?):
 

gcc -O3 -nostdlib -nodefaultlibs -fno-stack-protector -fno-builtin -nostdinc -O -g -m32 -Wall -I. -c -o boot.o bootsect.S
gcc -O3 -nostdlib -nodefaultlibs -fno-stack-protector -fno-builtin -nostdinc -O -g -m32 -Wall -I. -c -o main.o main.c
main.c: In function 'main':
main.c:9:6: warning: unused variable 'i' [-Wunused-variable]
ld ���T link.ld ���o kernel.bin main.o boot.o
ld: cannot find ���T: No such file or directory
link.ld: file not recognized: File format not recognized
make: *** [kernel.bin] Error 1

just in case heres the two files

 

bootsect.S

/**	Define basic assembler grub magic
**/
#define ASM 1
#define MULTIBOOT_HEADER_MAGIC 0xBADB002
#define MULTIBOOT_HEADER_FLAGS 0x00000003
#define STACK_SIZE 0X4000

/** Put an underscore before C extentions
**/
#ifdef HAVE_ASM_USCORE
#define	EXT_C(sym) _ 
#else
#define EXT_C(sym) sym
#endif

	.text
	.globl start
	
start:
	jmp multiboot_entry
	.align 4
	
multiboot_header:
	.long $MULTIBOOT_HEADER_MAGIC
	.long $MULTIBOOT_HEADER_FLAGS
	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
	
multiboot_entry:
	movl $(stack + STACK_SIZE),%esp
	call EXT_C(main)
	loop:
		hlt
		jmp loop
		
.section ".bss"
	.comm stack, STACK_SIZE

main.c

void main(void) {

	int i = 1 + 1;
	/**
	**/

}

i'm sure others have followed this small book as well, and hopefully the answer can help others as well!


Edited by Poe, 23 September 2014 - 08:11 PM.

"Portability is for those who can't write new programs" - Linus Torvalds


#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts

Posted 24 September 2014 - 04:27 AM   Best Answer

You are correct about formatting being the issue, but in the wrong place. Whatever encoding you are using for a single dash "-" is three bytes, and your terminal does not like it. Were you copying the example from somewhere that misencoded the character? Try to replace them with your own dashes to see if this resolves the issue.

 

As a programmer, try to look at the error as a stack, and dig backwards until you find the root cause of it:

ld ���T link.ld ���o kernel.bin main.o boot.o
ld
: cannot find ���T: No such file or directory
link
.ld: file not recognized: File format not recognized

 

This is not your linker putting out something misformatted, it appears to be reporting it is looking for a file named ???T and you must investigate it.

 

Why is T important? And what is the filename after it?

 

Look at the man page for ld: http://linux.die.net/man/1/ld

 

You can see that ld can use linker scripts with the switch -T, and the dash is clearly missing from the output, and therefor the dash must be the offending character (converted in to three bytes when put in an eight bit-per-character environment such as the common console)

 

Alexander.


Edited by Alexander, 24 September 2014 - 04:31 AM.

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 Poe

Poe

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 81 posts

Posted 24 September 2014 - 08:08 PM

You are correct about formatting being the issue, but in the wrong place. Whatever encoding you are using for a single dash "-" is three bytes, and your terminal does not like it. Were you copying the example from somewhere that misencoded the character? Try to replace them with your own dashes to see if this resolves the issue.

 

As a programmer, try to look at the error as a stack, and dig backwards until you find the root cause of it:

 

This is not your linker putting out something misformatted, it appears to be reporting it is looking for a file named ???T and you must investigate it.

 

Why is T important? And what is the filename after it?

 

Look at the man page for ld: http://linux.die.net/man/1/ld

 

You can see that ld can use linker scripts with the switch -T, and the dash is clearly missing from the output, and therefor the dash must be the offending character (converted in to three bytes when put in an eight bit-per-character environment such as the common console)

 

Alexander.

well, i'm not sure why but you were right.

After further invesitgation it appears the * and - were non unicode and the dash was the length of two for some odd reason.

 

All i did was rewrite the file and it worked perfect.


"Portability is for those who can't write new programs" - Linus Torvalds