Skip to content

_GLOBAL_OFFSET_TABLE_ symbol is not emitted for x86-64 #570

@parth-07

Description

@parth-07

We do not emit _GLOBAL_OFFSET_TABLE_ symbol for x86-64 target. This symbol is required for enabling GOT-relative addressing that is used for large code model.

Reproducer:

#!/usr/bin/env bash 

cat >1.c <<\EOF
extern int _GLOBAL_OFFSET_TABLE_;

int *v = &_GLOBAL_OFFSET_TABLE_;

int a;

int foo() { return a; }
EOF


clang -o 1.o -target x86_64-pc-linux-gnu 1.c -c -ffunction-sections -fPIC 
LDs=(ld.eld)
SFs=(eld)

for i in "${!SFs[@]}"; do
  ${LDs[$i]} -o lib1.${SFs[$i]}.so 1.o -shared
  ${LDs[$i]} -o 1.${SFs[$i]}.out 1.o
done

eld errors out with the below error, instead of implicitly providing the _GLOBAL_OFFSET_TABLE_ symbol.

Error: 1.o(.data+0x0): undefined reference to `_GLOBAL_OFFSET_TABLE_'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions