Skip to content

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

Open

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

Activity

  1. changed the title [-][BUG] local static referenes returns they address, instead of value[/-] [+][BUG] NDK r29: local static referenes returns they address, instead of value[/+] on Nov 20, 2025
  2. sr-tream commented on Nov 20, 2025

    @sr-tream
    Author

    The NDK r29 beta 2 29.0.13599879 is unaffected

  3. DanAlbert commented on Nov 21, 2025

    @DanAlbert
    Contributor

    Is this not a reference to a temporary that's immediately discarded? This looks like UB to me. @pirama-arumuga-nainar?

  4. sr-tream commented on Nov 21, 2025

    @sr-tream
    Author

    No, it's not a reference to tmp object. It's a reference created from a pointer to a global variable imported from another library

  5. DanAlbert commented on Nov 21, 2025

    @DanAlbert
    Contributor

    It's a reference to the dereferenced value of the global, which I think is a temporary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions