Author Topic: relocation truncated  (Read 6869 times)

Offline avajos

  • Jr. Member
  • *
  • Posts: 5
relocation truncated
« on: February 20, 2014, 09:14:20 AM »
recieving an error while linking a program

relocation truncated to fit: R_X86_64_8 against ' .bss'
relocation truncated to fit: R_X86_64_8 against ' .bss'

any advice in how to remove this error.??..
I think it is a memory related problem, but my code is not that big to cause a memory problem...

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: relocation truncated
« Reply #1 on: February 20, 2014, 11:08:29 AM »
I think I've seen this before. I think it comes from doing something like:
Code: [Select]
mov al, mybssvar
when you wanted to do:
Code: [Select]
mov al, [mybssvar]

There may be other causes for it. You may need to post some code (not necessarily all of it) before we can help you much. Look for someplace where a variable name in your .bss section is being treated as an 8-bit quantity.

Best,
Frank


Offline avajos

  • Jr. Member
  • *
  • Posts: 5
Re: relocation truncated
« Reply #2 on: February 21, 2014, 08:04:48 AM »
the program i have written is distributed in two files where members of the files are declared global and used in the other program..i have posted both of them..


Code: [Select]
;main program
global str1,str2, length1, length2, ptr1, ptr2,count1,count2
extern concat, substring

%macro print 2
mov rax, 1
mov rdi, 1
mov rsi, %1
mov rdx, %2
syscall
%endmacro

%macro accept 2
mov rax, 0
mov rdi, 0
mov rsi, %1
mov rdx, %2
syscall
%endmacro

SECTION .data

msg1: db "Enter first  string : "
len1: equ $-msg1
msg2: db "Enter second string : "
len2: equ $-msg2

SECTION .bss

str1: resb 7
str2: resb 7
ptr1: resb 7
ptr2: resb 7
length1: resb 3
length2: resb 3
count1 : resb 3
count2 : resb 3

SECTION .text

global_start:
_start:

print msg1,len1
accept str1,7
mov [length1],rax
sub byte[length1],01

mov rbx,[str1]
mov [ptr1],rbx

print msg2,len2
accept str2,7
mov [length2],rax
sub byte[length2],01

mov rbx,[str2]
mov [ptr2],rbx
call concat

call substring

mov rax, 60
mov rdi,0
syscall
;

Code: [Select]
;subordinate program
global str3, concat, substring
extern str1,str2,length1,length2,ptr1, ptr2,count1,count2

%macro print 2
mov rax, 1
mov rdi, 1
mov rsi, %1
mov rdx, %2
syscall
%endmacro

%macro accept 2
mov rax, 0
mov rdi, 0
mov rsi, %1
mov rdx,%2
syscall
%endmacro

SECTION .data
msg3: db "Length of substring should be less than the main string. "
len3: equ $-msg3
msg4: db "substring occurence : "
len4: equ $-msg4

SECTION .bss
str3 : resb 16
count : resb 3


SECTION .text
global_start:
_start:

concat:

mov  rsi,str1
mov rdi, str3

mov bl,[length1]
mov byte[count1],bl

loop1:

movsb
dec byte[count1]
cmp byte[count1],00h
jne loop1

mov rsi,str2
mov bl,[length2]
mov byte[count1],bl

loop2:

movsb
dec byte[count1]
cmp byte[count1],00h
jne loop2

print str3, 16
ret

substring:

mov al,length1
mov bl,length2

mov byte[count1],length1
mov byte[count2],length2

;mov byte[count1],al
;mov byte[count2],bl

mov bl,byte[count1]
mov cl,byte[count2]

cmp cl,bl
jg loop3

mov byte[count],00h
mov al,[ptr1]
;mov di,[ptr2]

compare:
cmp rax,[ptr2]
jne loop4

inc rax
inc byte[ptr2]
dec byte[count1]
dec byte[count2]
cmp byte[count2],00h
jne compare


mov rbx,[str2]
mov [ptr2],rbx
mov byte[count2],al
sub byte[count],01h
inc byte[count]
inc byte[ptr1]
jmp loop4

loop3:
print msg3,len3

loop4:
dec byte[count1]
cmp byte[count1],00h
jne compare
mov bl,byte[count]
call convascii

print msg4,len4
print count,3

ret

mov rax, 60
mov rdi,0
syscall

convascii:
mov rsi,count
mov rcx,10h

l3:
;rol rbx,04
mov al,bl
and al,0Fh
cmp al,09h
jbe add30
add al,07h

add30:
add al,30h
mov [rsi],al
;inc rsi
print rsi,3
;loop l3
ret
;

it is giving the above mentioned error for 'length 1' and 'length 2'
« Last Edit: February 21, 2014, 08:59:38 AM by Frank Kotler »

Offline avajos

  • Jr. Member
  • *
  • Posts: 5
Re: relocation truncated
« Reply #3 on: February 21, 2014, 08:24:44 AM »
it got solved..!!!....it was having exactly the same problem about putting the variable in brackets...

substring:

mov cl,[length1]
mov bl,[length2]

mov byte[count1],cl
mov byte[count2],bl

this is the correction made..!!..

Thanks a lot for helping..!! :) :)

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: relocation truncated
« Reply #4 on: February 21, 2014, 09:32:36 AM »
You've got more problems than that!

Code: [Select]
;...
SECTION .bss

str1: resb 7
str2: resb 7
ptr1: resb 7
ptr2: resb 7
length1: resb 3
length2: resb 3
count1 : resb 3
count2 : resb 3

Why 3? Why 7?  These seem like odd sizes for variables in a 64-bit program. I would think you'd use "resq 1" for most variables, unless there's some reason for them to be another size.

Code: [Select]
SECTION .text

global_start:
_start:

print msg1,len1
accept str1,7
mov [length1],rax

... and then you move 8 bytes into it. You do this in a lot of places. The sizes of the variables need to match the sizes of the registers they're used with before your code will run reliably. It may "work", but it's a bug waitin' to byte ya!

Best,
Frank