LLVM 13 static threadlocal error above -O0
jeaye opened this issue · 3 comments
jeaye commented
Overview
Given a static member function of a struct template, which returns a static threadlocal, Cling behaves correctly when the host program is compiled with -O0
, but not with anything greater, including -O1
.
Sample code
Modifying the cling-demo to look like the following reproduces the issue for me.
wrapper.hpp
#pragma once
template <typename T>
struct wrapper
{
static T& global()
{
thread_local static T t{};
return t;
}
};
main.cpp
#include <iostream>
#include <array>
#include <cling/Interpreter/Interpreter.h>
#include <cling/Interpreter/Value.h>
#include "wrapper.hpp"
int main(int const argc, char const **argv)
{
std::array<char const*, 2> cling_args{ argv[0], "-std=c++17" };
cling::Interpreter jit(cling_args.size(), cling_args.data(), LLVMDIR);
wrapper<int>::global() = 5;
jit.process("#include <iostream>");
jit.process("#include \"wrapper.hpp\"");
jit.process("std::cout << wrapper<int>::global() << std::endl;");
}
CMakeLists.txt
# Just tack on -O1 somewhere to trigger the issue.
target_compile_options(cling-demo PUBLIC -DLLVMDIR="${LLVM_BINARY_DIR}" -O1)
Program output
# With -O0
❯ ./cling-demo
5
# With -O1
❯ ./cling-demo
IncrementalExecutor::executeFunction: symbol '__emutls_v._ZZN7wrapperIiE6globalEvE1t' unresolved while linking [cling interface function]!
System details
Arch Linux, Cling built manually.
llvm_url="http://root.cern.ch/git/llvm.git"
llvm_branch="cling-patches-rrelease_13"
clang_url="http://root.cern.ch/git/clang.git"
clang_branch="cling-patches-rrelease_13"
cling_url="http://root.cern.ch/git/cling.git"
cling_branch="master" # commit da247bd77a92f0793abe95e10b373dbca7a7e5f1
jeaye commented
Hi! Following up on this since it's still an issue for me. Is there more info I can provide to help diagnose the problem?
hahnjo commented
Do I understand #483 (comment) correctly that this can be closed as well?
jeaye commented
Yes. The only outstanding issue related to these two is the lack of documentation for buiding cling. Most of it uses cpt.py, which overcomplicates things. The rest of it references three different cling repos (vassil's, root's own git server, and the new one on github).
I suspect the vast majority of cling users outside of root are not using the new monorepo, which means they will still see both of these issues with llvm 13.
…On June 25, 2023 4:50:33 AM PDT, Jonas Hahnfeld ***@***.***> wrote:
Do I understand #483 (comment) correctly that this can be closed as well?
--
Reply to this email directly or view it on GitHub:
#484 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>