Skip to content

LLVM uses R_X86_64_TPOFF32 relocations for large code model (-mcmodel=large), resulting in 'relocation truncated to fit' error #77128

Closed as not planned
@nmosier

Description

@nmosier

LLVM appears to generate R_X86_64_TPOFF32 relocations for accesses to thread-local variables, even when the large code model is enabled with the clang flag -mcmodel=large. This results in a linker error for programs that require >4GB thread-local data sections (.tdata and .tbss).

Here is an example program that fails to compile:

#define BUFSIZE (1024UL * 1024UL * 1024UL * 5UL)
_Thread_local char buf[BUFSIZE];
int main() {
  buf[BUFSIZE-1] = 0;
}

Compile as follows: clang -mcmodel=large test.c
Produces following error:

/tmp/user/20498/large-633e12.o: in function `main':
large.c:(.text+0xf): relocation truncated to fit: R_X86_64_TPOFF32 against symbol `buf' defined in .tbss section in /tmp/user/20498/large-633e12.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

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