How to add read-only section via linker script
Luca Boccassi
bluca@debian.org
Wed May 12 09:48:54 GMT 2021
On Tue, 2021-05-11 at 22:09 -0700, Fangrui Song wrote:
> On Mon, May 10, 2021 at 7:49 AM Luca Boccassi <bluca@debian.org> wrote:
> > On Mon, 2021-05-10 at 14:16 +0100, Nick Clifton wrote:
> > > Hi Luca,
> > >
> > > > Is there a way to make it read-only, _without_ having to compile some
> > > > object code and link it, but exclusively using the linker script?
> > >
> > > Short answer: no.
> > >
> > > There are a couple of possible solutions, but I doubt that they would
> > > be acceptable:
> > >
> > > * You could define a read-only segment and then assign the
> > > section to this segment.
> > >
> > > * Similarly you define a read-only memory region and assign
> > > the section to that.
> > >
> > > There is one other possible solution. You can specify the "type"
> > > of an output section in the linker script. Currently they can
> > > only be used to make the section non-loadable or non-allocateable.
> > > But you could always submit a patch to extend the linker to add
> > > a READONLY type, and then use that...
> > >
> > > Cheers
> > > Nick
> >
> > Thanks for the explanation!
> >
> > I've put together and tested a patch as suggested, seems to work fine.
> > Please have a look when you have a moment.
> >
> > https://sourceware.org/pipermail/binutils/2021-May/116567.html
> >
>
> Shouldn't https://sourceware.org/bugzilla/show_bug.cgi?id=26378 have
> made it possible to create a section (consiting of only
> BYTE/SHORT/LONG/QUAD) without the SHF_WRITE flag?
Hi,
Not sure - as the objdump -h output shows, I'm definitely getting the
section as read/write. This is causing issues in production testing,
due to SELinux being quite unhappy about it.
--
Kind regards,
Luca Boccassi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://sourceware.org/pipermail/binutils/attachments/20210512/d650b7cb/attachment-0001.sig>
More information about the Binutils
mailing list