From ddad187ce79305cd81fbe9d046de32e05836e134 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Wed, 21 Oct 2015 20:22:04 +0000 Subject: [PATCH] [RuntimeDyld] Ignore ST_FILE symbols when constructing GlobalSymbolTable Summary: ELF's STT_File symbols may overlap with regular globals in other files, so we should ignore them here in order to avoid having bogus entries in the symbol table that confuse us when resolving relocations. Reviewers: lhames Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D13888 llvm-svn: 250942 --- .../ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 3 ++- .../ExecutionEngine/RuntimeDyld/X86/ELF_STT_FILE.s | 14 ++++++++++++++ .../RuntimeDyld/X86/Inputs/ELF_STT_FILE_FILE.s | 3 +++ .../RuntimeDyld/X86/Inputs/ELF_STT_FILE_GLOBAL.s | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 llvm/test/ExecutionEngine/RuntimeDyld/X86/ELF_STT_FILE.s create mode 100644 llvm/test/ExecutionEngine/RuntimeDyld/X86/Inputs/ELF_STT_FILE_FILE.s create mode 100644 llvm/test/ExecutionEngine/RuntimeDyld/X86/Inputs/ELF_STT_FILE_GLOBAL.s diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 1c276a8728ad..f24a49e8b292 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -179,7 +179,8 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) { if (Flags & SymbolRef::SF_Exported) RTDyldSymFlags |= JITSymbolFlags::Exported; - if (Flags & SymbolRef::SF_Absolute) { + if (Flags & SymbolRef::SF_Absolute && + SymType != object::SymbolRef::ST_File) { auto Addr = I->getAddress(); Check(Addr.getError()); uint64_t SectOffset = *Addr; diff --git a/llvm/test/ExecutionEngine/RuntimeDyld/X86/ELF_STT_FILE.s b/llvm/test/ExecutionEngine/RuntimeDyld/X86/ELF_STT_FILE.s new file mode 100644 index 000000000000..50cc65079bd0 --- /dev/null +++ b/llvm/test/ExecutionEngine/RuntimeDyld/X86/ELF_STT_FILE.s @@ -0,0 +1,14 @@ +# RUN: llvm-mc -triple=x86_64-pc-linux -relocation-model=pic -filetype=obj -o %T/test_ELF_STT_FILE_FILE_x86-64.o %p/Inputs/ELF_STT_FILE_FILE.s +# RUN: llvm-mc -triple=x86_64-pc-linux -relocation-model=pic -filetype=obj -o %T/test_ELF_STT_FILE_GLOBAL_x86-64.o %p/Inputs/ELF_STT_FILE_GLOBAL.s +# RUN: llvm-mc -triple=x86_64-pc-linux -relocation-model=pic -filetype=obj -o %T/test_ELF_STT_FILE_x86-64.o %s +# RUN: llvm-rtdyld -triple=x86_64-pc-linux -verify %T/test_ELF_STT_FILE_GLOBAL_x86-64.o %T/test_ELF_STT_FILE_FILE_x86-64.o %T/test_ELF_STT_FILE_x86-64.o + +# Test that RTDyldELF ignores STT_FILE symbols, and in particular does +# crash if we are relocating against a symbol that happens to have the +# same name as an STT_FILE symbol. + +_main: + movq foo.c@GOTPCREL(%rip), %rax + movq bar.c@GOTPCREL(%rip), %rax + movq $0, %rax + retq diff --git a/llvm/test/ExecutionEngine/RuntimeDyld/X86/Inputs/ELF_STT_FILE_FILE.s b/llvm/test/ExecutionEngine/RuntimeDyld/X86/Inputs/ELF_STT_FILE_FILE.s new file mode 100644 index 000000000000..7280c51b5867 --- /dev/null +++ b/llvm/test/ExecutionEngine/RuntimeDyld/X86/Inputs/ELF_STT_FILE_FILE.s @@ -0,0 +1,3 @@ +.file "foo.c" +.global bar.c +bar.c: diff --git a/llvm/test/ExecutionEngine/RuntimeDyld/X86/Inputs/ELF_STT_FILE_GLOBAL.s b/llvm/test/ExecutionEngine/RuntimeDyld/X86/Inputs/ELF_STT_FILE_GLOBAL.s new file mode 100644 index 000000000000..a7e5342746e2 --- /dev/null +++ b/llvm/test/ExecutionEngine/RuntimeDyld/X86/Inputs/ELF_STT_FILE_GLOBAL.s @@ -0,0 +1,2 @@ +.global foo.c +foo.c: