[llvm-dev] Storing "blockaddress(@function, %block)" in a global variable?

Kostya Serebryany via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 28 18:03:24 PDT 2017


Hi,

The LangRef warns that "blockaddress(@function, %block)" has a limited and
target-dependent applicability:
https://llvm.org/docs/LangRef.html#addresses-of-basic-blocks

But I wanted very much to save addresses of blocks in a global variable and
so I did:

% cat cond.c
void foo(long *a) { if (a) *a = 0; }

% clang -O1  -c  cond.c   -fsanitize-coverage=inline-8bit-counters,pc-table
-S -o - -emit-llvm

@__sancov_gen_.1 = private constant [3 x i8*] [i8* bitcast (void (i64*)*
@foo to i8*), i8* blockaddress(@foo, %entry.if.end_crit_edge), i8*
blockaddress(@foo, %if.then)], section "__sancov_pcs", align 8

Is this expected to work?
If not, is it reasonable to try to make it work?

This works almost as I want it to, but not quite entirely:
% cat cout.cpp
#include <iostream>
void Foo() { std::cout << ""; }

% clang++   -fsanitize-coverage=inline-8bit-counters,pc-table cout.cpp -O1
fatal error: error in backend: Undefined temporary symbol

(the error message was added in
http://llvm.org/viewvc/llvm-project?view=revision&revision=253328 by Oliver
Sstannard, CC-ed)

The error comes from lib/MC/ELFObjectWriter.cpp
and it disappears with -O0 or -O2 or -no-integrated-as

Thanks!

--kcc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170728/c8cb27a2/attachment.html>


More information about the llvm-dev mailing list