Hello,
I wish to link several .o files to make only one .o file not executable (it will relinked later). I would like to first make a prelinked file easier to then link them to the excutable file (ie. with a main).
Thank for your help.
On Sun, 1 May 2011 18:47:14 +0100 (BST) Patrick Dupre wrote:
I wish to link several .o files to make only one .o file not executable (it will relinked later). I would like to first make a prelinked file easier to then link them to the excutable file (ie. with a main).
ld -r can do that, but are you sure you don't just want to stick all the .o files in an archive with ar and link with that static library later?
On 05/01/2011 01:51 PM, Tom Horsley wrote:
On Sun, 1 May 2011 18:47:14 +0100 (BST) Patrick Dupre wrote:
I wish to link several .o files to make only one .o file not executable (it will relinked later). I would like to first make a prelinked file easier to then link them to the excutable file (ie. with a main).
ld -r can do that, but are you sure you don't just want to stick all the .o files in an archive with ar and link with that static library later?
Sounds more like a shared library not static to me ...
On Sun, 01 May 2011 13:58:53 -0400 Genes MailLists wrote:
Sounds more like a shared library not static to me ...
Could be, in which case you need different options and programs. For one thing you probably want to compile the objects with -fpic (I don't right offhand remember the options for linking a shared library to generate the .so file).
On 05/01/11 11:03, Tom Horsley wrote:
On Sun, 01 May 2011 13:58:53 -0400 Genes MailLists wrote:
Sounds more like a shared library not static to me ...
Could be, in which case you need different options and programs. For one thing you probably want to compile the objects with -fpic (I don't right offhand remember the options for linking a shared library to generate the .so file).
Example: g++ -shared -Wl,-soname,libMyLib.so.1 -o libMyLib.so.1 foo1.o [foo2.o....fooN.o] -lc [ -lSOMEOTHERLIB -l...]
On 05/01/11 10:51, Tom Horsley wrote:
On Sun, 1 May 2011 18:47:14 +0100 (BST) Patrick Dupre wrote:
I wish to link several .o files to make only one .o file not executable (it will relinked later). I would like to first make a prelinked file easier to then link them to the excutable file (ie. with a main).
ld -r can do that, but are you sure you don't just want to stick all the .o files in an archive with ar and link with that static library later?
Well, I actually have seen this in several makefiles where several .o's are linked into a single big .o This is useful when you are building, say, a kernel module. For example:
crypto-rsl.o: arc4.o api.o autoload.o cipher.o compress.o digest.o scatterwalk.o proc.o $(LD) -r $^ -o $@
Also, vmlinux itself is created in this way.
Thank,
I does help. However, I have another problem, and I not sure that it is does to the linker. It is a perl application calling my own c routines. I made tons of them but here I get:
Can't load '/home/pdupre/perl_lib/i386-linux-thread-multi/auto/Absor_satur/Absor_satur.so' for module Absor_satur: /home/pdupre/perl_lib/i386-linux-thread-multi/auto/Absor_satur/Absor_satur.so: cannot restore segment prot after reloc: Permission denied at /usr/lib/perl5/DynaLoader.pm line 200. at ./Profile.pl line 22
I do not know how to debug this !
I wish to link several .o files to make only one .o file not executable (it will relinked later). I would like to first make a prelinked file easier to then link them to the excutable file (ie. with a main).
ld -r can do that, but are you sure you don't just want to stick all the .o files in an archive with ar and link with that static library later?
On Sun, 1 May 2011, Patrick Dupre wrote:
It is a perl application calling my own c routines. I made tons of them but here I get:
Can't load '/home/pdupre/perl_lib/i386-linux-thread-multi/auto/Absor_satur/Absor_satur.so' for module Absor_satur: /home/pdupre/perl_lib/i386-linux-thread-multi/auto/Absor_satur/Absor_satur.so: cannot restore segment prot after reloc: Permission denied at /usr/lib/perl5/DynaLoader.pm line 200. at ./Profile.pl line 22
It looks like you might have run afoul of an anti-stack-smashing mechanism. One idea is to mark some parts of memory non-executable. That limits the places to where evil folks can do a pseudo-return. Another idea is to rearrange the places where shared objects are stored. This limits the information avaiable to an evil-doer. An unrelocateable shared object sometimes gets evicted.
I do not know how to debug this !
I wish to link several .o files to make only one .o file not executable (it will relinked later). I would like to first make a prelinked file easier to then link them to the excutable file (ie. with a main).
ld -r can do that, but are you sure you don't just want to stick all the .o files in an archive with ar and link with that static library later?
I've read the linking with -r is *not* the same as just "concatenating", but I'm not sure what the difference is.
You can make an archive.a and use -whole when listing it for inclusion.