Open
Description
Setting the output section of a variable by attribute in a module interface causes miscompilation.
Code works fine if not using c++ modules or if removing section attribute.
Example
test.ccm:
export module test;
int foo __attribute__((section(".data.foo"))) = 2;
export int get_foo()
{
return foo;
}
export void set_foo(int val)
{
foo = val;
}
main.cc:
import test;
int main()
{
set_foo(5);
return get_foo();
}
Compile and run:
clang++ -std=c++23 -O1 -c test.ccm -fmodule-output=test.pcm
clang++ -std=c++23 -O1 -c main.cc -fmodule-file=test=test.pcm
clang++ test.o main.o -o test
./test
echo $?
Expected result:
5
Actual result:
2
Clang version
clang++ --version
clang version 19.1.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin