Page 1 of 1

relocation truncated to fit: R_X86_64_32S

Posted: Mon Nov 09, 2015 12:41 am
by tsdnz
EDIT: Solved, thank-you John.

Hi all, I have search this on the Wiki and google.

I am implementing a new exception handler in user space and this error is happening.
A nudge or a kick in the right direction would be appreciated.

Edit: There are no linked files.

Here is the code, I am trying to get the label address.
It compiles in the Kernel which is loaded under 4GB.
This line breaks it??? asm volatile ("mov ExceptionLabel, %rax;");

Code: Select all

#define DEBUG 1
#undef RELEASE
#else
#define RELEASE 1
#undef DEBUG
#endif

#pragma GCC diagnostic ignored "-Wunused-label";

extern "C" void StartKernel(void) /*!!__attribute__((section(".StartKernel")))!!*/;
char FileEnd /*!!__attribute__((section(".FileEnd")))!!*/;

void StartKernel(void)
{
	// Header for Kernel, nice and simple
	QWORD pStartKernel = (QWORD)&StartKernel;
	asm volatile (";" : : "a" (pStartKernel), "b"(&FileEnd));
	// End of header

	while (true)
	{
		asm volatile ("mov	ExceptionLabel, %rax;");
ExceptionLabel:
		asm volatile ("ExceptionLabel:");
	}
}
Here is linked.ld

Code: Select all

ENTRY(StartKernel)
SECTIONS
{
	. = 0x170000000000;

	.GDT 0x5000 (NOLOAD) :
	{
		*(.GDT)
	}

	.LocalAPICAddress 0x48A0 (NOLOAD) :
	{
		*(.LocalAPICAddress)
	}

	.DefaultExceptionHandler14 0x48A8 (NOLOAD) :
	{
		*(.DefaultExceptionHandler14)
	}

	.DefaultExceptionHandler0 0x48B0 (NOLOAD) :
	{
		*(.DefaultExceptionHandler0)
	}

	.DefaultExceptionHandler19 0x48B8 (NOLOAD) :
	{
		*(.DefaultExceptionHandler19)
	}

	.CPU_ExceptionHandler_RecoveryCodePointer 0x30000 (NOLOAD) :
	{
		*(.CPU_ExceptionHandler_RecoveryCodePointer)
	}

	.StartKernel 0x170000000000 :
	{
		*(.StartKernel)
	}

	.UserData :
	{
		. = ALIGN(16);
		*(.UserData)
	}

	.text :
	{
		. = ALIGN(16);
		*(.text)
	}

	.rodata : 
	{
		. = ALIGN(16);
		*(.rodata)
	}

	.bss : 
	{
		. = ALIGN(16);
		*(COMMON)
		*(.bss)
	}

	.staticmemory (NOLOAD) : 
	{
		. = ALIGN(16);
		*(.staticmemory)
	}

	.FileEnd (NOLOAD) :
	{
		*(.FileEnd)
	}

}
The compiler:

Code: Select all

x86_64-elf-g++ -c 192_168_99_44.cpp -o 192_168_99_44.o -ffast-math -fno-exceptions -mcmodel=large -fno-rtti -ffreestanding -mno-red-zone -Ofast -Wall -Wextra -nostdlib -m64 -std=c++11 -msse3 -msse2 -mmmx -msse -mno-3dnow -fstrength-reduce -fomit-frame-pointer -finline-functions -fno-tree-loop-distribute-patterns -funroll-loops 2> Compile.txt
The linker:

Code: Select all

x86_64-elf-g++ -T linker.ld -o 192_168_99_44.lkr 192_168_99_44.o -lgcc -nostdlib -fno-use-linker-plugin 2> Linker.txt

Re: relocation truncated to fit: R_X86_64_32S

Posted: Mon Nov 09, 2015 12:52 am
by Combuster
It compiles in the Kernel which is loaded under 4GB.
0x170000000000
Nope.

Re: relocation truncated to fit: R_X86_64_32S

Posted: Mon Nov 09, 2015 1:08 am
by tsdnz
Thanks for the response, this is UserSpace code.

It is told to run at 0x170000000000, the kernel is working fine when compiled below 4GB.

Edit, this is just code to show the error I am dealing with.
Combuster wrote:
It compiles in the Kernel which is loaded under 4GB.
0x170000000000
Nope.

Re: relocation truncated to fit: R_X86_64_32S

Posted: Mon Nov 09, 2015 1:24 am
by tsdnz
This code works fine, looks to be just a label is the issue.

Oh well, will have to redesign it to suit.....

Code: Select all

// Do not change, automatically set by compiler
#define SolutionConfiguration_Debug 1
#define SolutionConfiguration_Release 2
#define SolutionConfiguration SolutionConfiguration_Debug

#if SolutionConfiguration == SolutionConfiguration_Debug
#define DEBUG 1
#undef RELEASE
#else
#define RELEASE 1
#undef DEBUG
#endif

#pragma GCC diagnostic ignored "-Wunused-label";

extern "C" void StartKernel(void) /*!!__attribute__((section(".StartKernel")))!!*/;
char FileEnd /*!!__attribute__((section(".FileEnd")))!!*/;

#include "Generic.h"

void MyCode()
{
	asm volatile ("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");
}

void StartKernel(void)
{
	// Header for Kernel, nice and simple
	QWORD pStartKernel = (QWORD)&StartKernel;
	asm volatile (";" : : "a" (pStartKernel), "b"(&FileEnd));
	// End of header

	while (true)
	{
		asm volatile (";" : : "a"(MyCode));
	}
}

Re: relocation truncated to fit: R_X86_64_32S

Posted: Mon Nov 09, 2015 1:26 am
by jnc100
The mov instruction (in at&t syntax) expects a 32-bit offset. Thus the assembler generates a 32 bit relocation type for it. If you try and fit a 64-bit address into it then you will get errors. Try using movabs instead, or better yet avoid inline assembler altogether when you can achieve the same with plain C (or a mix with separate assembler files).

Regards,
John.

Re: relocation truncated to fit: R_X86_64_32S

Posted: Mon Nov 09, 2015 1:31 am
by tsdnz
Alright mate, that's perfect. I should have asked a few hours ago....

Many thanks to all..
jnc100 wrote:The mov instruction (in at&t syntax) expects a 32-bit offset. Thus the assembler generates a 32 bit relocation type for it. If you try and fit a 64-bit address into it then you will get errors. Try using movabs instead, or better yet avoid inline assembler altogether when you can achieve the same with plain C (or a mix with separate assembler files).

Regards,
John.