Skip to content

[BUG] NDK r29: local static referenes returns they address, instead of value #2213

@sr-tream

Description

@sr-tream

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");
  1. Assign the symbol to a local static reference inside a function:
void foo(){
  static auto &variable_name = *reinterpret_cast<int*>(ptr_to_var);
}
  1. Reading the reference returns the address rather than the value:
int foo(){
  static auto &variable_name = *reinterpret_cast<int*>(ptr_to_var);
  return variable_name; // returns `reinterpret_cast<int>(&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<int*>(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

  • I have checked and the NDK I'm using is currently supported

Affected versions

r29

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions