[llvm-dev] Zero-sized globals in LLVM IR
Manuel Jacob via llvm-dev
llvm-dev at lists.llvm.org
Tue Jul 17 12:07:32 PDT 2018
How did you come to the conclusion that a zero-length array generates
something of at least of size 1? I don't see a significant difference
between the assembly output of "@a1 = global [0 x i8] []" and "@a2 =
global {} {}".
.type a1, at object # @a1
.data
.globl a1
a1:
.size a1, 0
.type a2, at object # @a2
.bss
.globl a2
.p2align 3
a2:
.size a2, 0
Subjectively, I'd consider "@a2 = global {} {}" to be the "idiomatic"
way to define a zero-sized global. IMHO it shouldn't trigger an
assertion.
On 2018-07-17 12:58, David Chisnall via llvm-dev wrote:
> Hello the list,
>
> What is the correct type for a global of size zero? I need the
> compiler to be able to generate one, so that the linker will insert it
> at a specific position without perturbing the location of anything
> else in the section. I have tried a zero-length array (generates
> something at least one byte). At Nuno’s suggestion, I tried a
> structure with no fields. In release builds, this works correctly,
> but in debug builds it triggers an assertion that the type must be
> sized.
>
> What is the recommended way of doing this?
>
> David
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list