Page MenuHomePhabricator

Make -fno-pic respect -fno-direct-access-external-data

Authored by MaskRay on Dec 4 2020, 7:59 PM.



D92633 added -f[no-]direct-access-external-data to supersede -m[no-]pie-copy-relocations.
(The option works for -fpie but is a no-op for -fno-pic and -fpic.)

This patch makes -fno-pic -fno-direct-access-external-data drop dso_local from
global variable declarations. This usually causes the backend to emit a GOT
indirection for external data access. With a GOT relocation, the subsequent
-no-pie link will not have copy relocation even if the data symbol turns out to
be defined by a shared object.

// a.c
extern int var;
int foo() { return var; }

clang  a.c -S -o - => movl    var, %eax

clang -fno-direct-access-external-data a.c -S -o - => movq    var@GOTPCREL, %rax; movl    (%rax), %eax
// The same as -fpie or -fpic

Diff Detail

Unit TestsFailed

1,900 msx64 debian > libarcher.races::lock-unrelated.c
Script: -- : 'RUN: at line 13'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang -fopenmp -pthread -fno-experimental-isel -g -O1 -fsanitize=thread -I /mnt/disks/ssd0/agent/llvm-project/openmp/tools/archer/tests -I /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/runtime/src -L /mnt/disks/ssd0/agent/llvm-project/build/lib -Wl,-rpath,/mnt/disks/ssd0/agent/llvm-project/build/lib /mnt/disks/ssd0/agent/llvm-project/openmp/tools/archer/tests/races/lock-unrelated.c -o /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/lock-unrelated.c.tmp -latomic && env TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1' /mnt/disks/ssd0/agent/llvm-project/openmp/tools/archer/tests/deflake.bash /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/lock-unrelated.c.tmp 2>&1 | tee /mnt/disks/ssd0/agent/llvm-project/build/projects/openmp/tools/archer/tests/races/Output/lock-unrelated.c.tmp.log | /mnt/disks/ssd0/agent/llvm-project/build/./bin/FileCheck /mnt/disks/ssd0/agent/llvm-project/openmp/tools/archer/tests/races/lock-unrelated.c

Event Timeline

MaskRay requested review of this revision.Dec 4 2020, 7:59 PM
MaskRay created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2020, 7:59 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MaskRay edited the summary of this revision. (Show Details)Dec 4 2020, 8:05 PM

This is straightforward, too :)

MaskRay updated this revision to Diff 315575.Jan 9 2021, 12:19 AM

Improve tests

This revision was not accepted when it landed; it landed in state Needs Review.Jan 9 2021, 12:32 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.