How to add read-only section via linker script

Luca Boccassi bluca@debian.org
Mon May 10 14:49:12 GMT 2021


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

Thank you!

-- 
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/20210510/a3112b4b/attachment-0001.sig>


More information about the Binutils mailing list