I'm recently starting an assignment for a class, and I'm trying to implement my program but I cannot get it to compile for testing. I can't figure out what to do with the error I'm getting nor what it means.
/usr/bin/ld: /tmp/ccPPQgOb.o: relocation R_X86_64_32S against `.data'
can not be used when making a shared object; recompile with -fPIC
Makefile:4: recipe for target 'cmix' failed
/usr/bin/ld: final link failed: Nonrepresentable section on output
This is my func.S file, still missing mostly a bunch of functions to be implemented later. switchBytes should switch some bytes around and then print an integer
.data
format: .asciz "%d\n"
.global printHigher, countOnes, lowerToUpper
.text
.globl switchBytes
.type switchBytes, @function
switchBytes:
mov $0xFF, %r12
lea (,%rdi,8), %r13
mov %r13b, %cl
shl %cl, %r12
andq %rdx,%r12
mov %rsi, %r14
subq %rdi,%r14 #y-x
lea (,%r14,8), %r14
mov %r14b,%cl
shl %cl,%r12
mov $0xFF, %r13
lea (,%rsi,8), %r10
mov %r10b, %cl
shl %cl, %r13
andq %rdx, %r13
mov $0xFF, %r14
lea (,%rdi,8), %r10
mov %r10b, %cl
shl %cl, %r14
notq %r14
andq %r14,%rdx
mov $0xFF, %r15
lea (,%rsi,8), %r10
mov %r10b, %cl
shl %cl, %r15
notq %r15
andq %r15,%rdx
orq %r12,%rdx
lea (,%rdi,8), %r10
mov %r10b, %cl
sar %cl, %r13
orq %r13, %rdx
mov $format, %rdi
mov %rdx, %rsi
mov $0, %eax
call printf
mov %rdx,%rax
ret
printHigher:
ret
countOnes:
ret
lowerToUpper:
ret
This is my Makefile
all: cmix
cmix:
$gcc cmix.c func.S -o cmix
clean:
rm -f cmix.o cmix
rm -f a.out
This is my cmix.c (main)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
void switchBytes(int, int, int); //rdi,rsi,rdx
void printHigher(unsigned int *, int); //rdi,rsi
void countOnes(int); //rdi
void lowerToUpper(char *); //rdi
int main(int argc, char *argv[]) { //main
char *opcion = argv[2];
int c,i;
int primerNum,segundoNum,tercerNum;
while ((c = getopt(argc, argv, "o:")) != -1)
switch (c)
{
case 'o':
if (strcmp("switch",opcion) == 0) {
primerNum = atoi(argv[3]);
segundoNum = atoi(argv[4]);
tercerNum = atoi(argv[5]);
switchBytes(tercerNum,primerNum,segundoNum);
exit(0);
}
else if (strcmp("higher",opcion) == 0) {
unsigned int* data;
data = malloc(argc*4);
for (int i = 3; i < argc; i++) {
data[(i-3)] = (unsigned int)atoi(argv[i]);
}
printHigher(data, argc-3);
exit(0);
}
else if (strcmp("count",opcion) == 0) {
primerNum = atoi(argv[3]);
countOnes(primerNum);
exit(0);
}
else if (strcmp("l2u",opcion) == 0) {
int strsize = 0;
for (i = 3; i < argc; i++) {
strsize += strlen(argv[i]);
if (argc > i+1)
strsize++;
}
char *cmdstring;
cmdstring = malloc(strsize);
cmdstring[0] = '\0';
for (i = 3; i < argc; i++) {
strcat(cmdstring, argv[i]);
if (argc > i+1)
strcat(cmdstring, " ");
}
lowerToUpper(cmdstring);
exit(0);
}
else {
printf("Opcion Invalida\n");
break;
}
default:
abort();
}
return 0;
}