link_section is not applied to global constants #46968
Labels
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The
link_section
attribute doesn't get applied to globalconst
values.Consider the following program (which uses
static
instead ofconst
, and correctly applies thelink_section
toHELLO
):As can be seen in the LLVM IR (Playground link),
HELLO
is correctly given the custom section assignment:But if we change
HELLO
to be aconst
instead ofstatic
:Then the string no longer has the custom section applied (Playground link):
I think that Rust should propagate the link section to all instances of the string. That is,
@byte_str.0
(and any other duplicate instances of theconst
) should be defined as@byte_str.0 = private unnamed_addr constant [6 x i8] c"hello\00", section ".data,__yes_this_is_a_custom_link_section", align 8
.Meta info: I've tested this in both 1.22.1 and 1.24.0-nightly (2017-12-22 5165ee9). Both produce the same results.
The text was updated successfully, but these errors were encountered: