Skip to content

Android link error: relocation R_ARM_TLS_LE32 against tl.foo cannot be used with -shared #17575

@tuket

Description

@tuket

Zig Version

0.12.0-dev.983+78f2ae7f2

Steps to Reproduce and Observed Behavior

Take this program:

// tl.zig
const std = @import("std");

threadlocal var foo: std.Thread.Id = 0;

export fn setFoo() void {
    foo = std.Thread.getCurrentId();
}

export fn getFoo() std.Thread.Id {
    return foo;
}

We can build a shared lib for linux with the following command:

zig.exe build-lib -target arm-linux -dynamic -fPIC tl.zig

The previous command compiles fine.

Now if we change arm-linux to arm-linux-android:

zig.exe build-lib -target arm-linux-android -dynamic -fPIC tl.zig

We get the following compile error:

error: ld.lld: relocation R_ARM_TLS_LE32 against tl.foo cannot be used with -shared
    note: defined in libtl.so.o
    note: referenced by tl.zig:0
    note:               libtl.so.o:(setFoo)
error: ld.lld: relocation R_ARM_TLS_LE32 against tl.foo cannot be used with -shared
    note: defined in libtl.so.o
    note: referenced by tl.zig:0
    note:               libtl.so.o:(getFoo)
error: ld.lld: relocation R_ARM_TLS_LE32 against Thread.LinuxThreadImpl.tls_thread_id cannot be used with -shared
    note: defined in libtl.so.o
    note: referenced by Thread.zig:0 (C:\Users\tuket\Documents\APPS\zig_experimental\lib\std/Thread.zig:0)
    note:               libtl.so.o:(Thread.LinuxThreadImpl.getCurrentId)
error: ld.lld: relocation R_ARM_TLS_LE32 against debug.panic_stage cannot be used with -shared
    note: defined in libtl.so.o
    note: referenced by debug.zig:0 (C:\Users\tuket\Documents\APPS\zig_experimental\lib\std/debug.zig:0)
    note:               libtl.so.o:(debug.panicImpl)

However, if we run the same command with zig 0.11.0, it compiles fine.

Expected Behavior

I'm not certain what should be the expected behavior, but it's weird that it used to work and now it doesn't.

This is preventing me from compiling Android apps.

For this bud report, I tried to make the program as simple as possible.

In my more elaborate Android program, I wasn't actually using the std.Thread.getCurrentId() function. In fact, when I would add the "-Drelease" flag to zig, the compiler error would go away (probably due to unused code elimination).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavioros-androidAndroid (Linux variant)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions