relocation truncated to fit: R_X86_64_32S

Programming, for all ages and all languages.
Post Reply
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

relocation truncated to fit: R_X86_64_32S

Post 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
Last edited by tsdnz on Mon Nov 09, 2015 1:57 am, edited 1 time in total.
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: relocation truncated to fit: R_X86_64_32S

Post by Combuster »

It compiles in the Kernel which is loaded under 4GB.
0x170000000000
Nope.
"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 ]
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: relocation truncated to fit: R_X86_64_32S

Post 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.
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: relocation truncated to fit: R_X86_64_32S

Post 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));
	}
}
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: relocation truncated to fit: R_X86_64_32S

Post 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.
tsdnz
Member
Member
Posts: 333
Joined: Sun Jun 16, 2013 4:09 am

Re: relocation truncated to fit: R_X86_64_32S

Post 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.
Post Reply