[BUG] NDK r29: local static referenes returns they address, instead of value
- Dominant language
- No language data
- Stars
- 2.3k
- Forks
- 310
- PR merge metrics
- No merged PRs in 30d
Description
### Description
Static references to symbols obtained via dlsym behave unexpectedly in the latest release (29.0.14206865). Instead of returning the value of the variable, reading the static reference appears to return the address.
## Steps from my environment
1. Retrieve symbol pointer:
```
auto ptr_to_var = dlsym(pLib, "variable_name");
```
2. Assign the symbol to a local static reference inside a function:
```
void foo(){
static auto &variable_name = *reinterpret_cast(ptr_to_var);
}
```
3. Reading the reference returns the address rather than the value:
```
int foo(){
static auto &variable_name = *reinterpret_cast(ptr_to_var);
return variable_name; // returns `reinterpret_cast(&variable_name)` instead of value of variable_name
}
```
### Workaround
Passing the reference as an rvalue argument to a function seems to behave correctly:
```
void bar(int &&variable_name){
// reference reads correct
}
void foo(){
static auto &variable_name = *reinterpret_cast(ptr_to_var);
bar(variable_name);
}
```
A minimal test case could not be constructed, but the bug is reproducible in real usage as described above.
### I am using a supported NDK
- [x] I have checked and the NDK I'm using is currently supported
### Affected versions
r29
Contributor guide
Assessment
This issue has not been assessed yet.