1

I write this command:

gcc drr.c -o drr -pthread -lcdsl -L./../synch_implementations -I./../synch_implementations

And I can't understand why I get this response:

usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_queue_list.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_deque_list.o): relocation R_X86_64_32S against symbol `cdsl_deque_list_lock_based_pthread_push_tail' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_lock.o): relocation R_X86_64_32S against symbol `cdsl_pthread_lock_request' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: final link failed: Nonrepresentable section on output
ollect2: error: ld returned 1 exit status

Can anyone help me understand what is wrong?

Notes:

1)I use ubuntu (via VirtualBox).

2)I am very inexperienced, so probably this is not a very bright question.

DanB
  • 2,022
  • 1
  • 12
  • 24
Chrysa
  • 11
  • 1
  • 3
  • *Position Independent Code* https://stackoverflow.com/questions/39198826/what-does-the-fpic-compilation-flag-does – ron Feb 28 '19 at 20:15
  • https://en.wikipedia.org/wiki/Position-independent_code – ron Feb 28 '19 at 20:15

1 Answers1

0

Solution: When you compile ./../synch_implementations/libcdsl.a you need to add an extra "-fPIC" flag to produce position-independent-code (see comments above).

Note: The PIC flag is in general needed when producing library object code since it creates objects relative to a global offset table (GOT) which subsequently allows to link library objects with your code.

Ralf Ulrich
  • 1,575
  • 9
  • 25