OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 9:12 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: relocation truncated to fit: R_X86_64_32S
PostPosted: Mon Nov 09, 2015 12:41 am 
Offline
Member
Member

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

Top
 Profile  
 
 Post subject: Re: relocation truncated to fit: R_X86_64_32S
PostPosted: Mon Nov 09, 2015 12:52 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
It compiles in the Kernel which is loaded under 4GB.
Quote:
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 ]


Top
 Profile  
 
 Post subject: Re: relocation truncated to fit: R_X86_64_32S
PostPosted: Mon Nov 09, 2015 1:08 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: relocation truncated to fit: R_X86_64_32S
PostPosted: Mon Nov 09, 2015 1:24 am 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
This code works fine, looks to be just a label is the issue.

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

Code:
// 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));
   }
}


Top
 Profile  
 
 Post subject: Re: relocation truncated to fit: R_X86_64_32S
PostPosted: Mon Nov 09, 2015 1:26 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
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.

_________________
Tysos | rpi-boot


Top
 Profile  
 
 Post subject: Re: relocation truncated to fit: R_X86_64_32S
PostPosted: Mon Nov 09, 2015 1:31 am 
Offline
Member
Member

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 77 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group