Skip to content
Advertisement

How to embed data in shared library?

For example, I want to embed dicmap.bin to a shared library libxxx.so. I write a program to verify it.

JavaScript
JavaScript

But its _start, _end and _size is invalid.

JavaScript

end-start and size should be sizeof dicmap.bin (198600798).

My objcopy is binutils-2.30-54.el7 of rhel7 with devtoolset-8.

I try to add share flags to the .o file, but a error happens:

JavaScript

binutils-2.27-41.base.el7_7.1.x86_64 of rhel7 also have the same problem.

Is there any method to help me?

Advertisement

Answer

There 2 methods works for me now.

Method 1: Use objcopy to convert data to “.o”, then link to “.so”. Then link the “.so” and main code with “-fPIC”.

JavaScript

Method 2: Use assmbler to wrap the data, and store the size in a different way of objcopy.

JavaScript

Codes:

test_dicmap.cpp:

JavaScript

test_dicmap3.cpp:

JavaScript

dicmap3.s:

JavaScript

dicmap.bin:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement