uuu777
uuu777

Reputation: 901

Shared const data segment

We have to share a large chunk of compile-time known data between processes. Is it possible to put into .rodata section of a shared library? What are the practical steps to do so?

Upvotes: 0

Views: 187

Answers (1)

Employed Russian
Employed Russian

Reputation: 213576

Is it possible to put into .rodata section of a shared library?

Yes.

What are the practical steps to do so?

If you declare the data const, compiler should already do it for you.
If that isn't already happening, please ask a separate question with an MCVE.

Or do you mean: "I have a data file which I'd like to include verbatim into my foo.so, without first transforming that data into a C-style array and compiling it?"

In that case, do this:

// foo.S
    .globl foo_data
    .section .rodata
foo_data:
    .incbin "foo.data"

compile foo.S and link it into your shared library.

Upvotes: 1

Related Questions