Place &str in specific linker sections #70239
Labels
A-linkage
Area: linking into static, shared libraries and binaries
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
In the usecase I am working on I want to store the string from
core::any::type_name
in a specific linker section to create an instrumentation tool for Embedded Rust micro controllers.If the string is placed in
.rodata
it does not affect the tool, but when having only a few kB of memory storing these strings in the actual micro controller is a huge price to pay.Rather only the generated ELF file, which the host can read, should have this info (i.e. in an
INFO
marked section).As it is today one can place variables in specific sections as:
However, this is not possible for
&str
, the following:Will place the string itself in
.rodata
, while placing the pointer and length in the section.my_section
.The recommended solution is to place the string in an array using something similar to the following:
However this does not work on strings given from (non-const-fn) functions such as
core::any::type_name
, and the function take no arguments so the string must be coming from a literal somewhere.Is there a way to make the strings from
core::any::type_name
(or similar functions) be placed in a specific linker section?As the string is being placed in
.rodata
something is controlling this placement, I simply wish to change this.The method stated above works in nightly, as one can use the
#![feature(const_type_name)]
feature to get the string as a const-fn. However I am unable to reproduce this in any way using stable rust.Example playground of the nightly version: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d5f5c7fbe90194640bd1918cc068c2db
The text was updated successfully, but these errors were encountered: