[llvm-dev] why do undefined globals end up in .data instead of .bss?

Andrew Kelley via llvm-dev llvm-dev at lists.llvm.org
Tue Apr 25 13:48:56 PDT 2017

On Tue, Apr 25, 2017 at 4:41 PM, Tobias Edler von Koch <
tobias at codeaurora.org> wrote:

> On 04/24/2017 01:55 PM, Andrew Kelley via llvm-dev wrote:
> I see, thanks. Would a patch be welcome which changed this behavior? Or I
> suppose I could emit zeroinitializer instead of undef. But it seems like
> undef is the more correct value.
> Are you producing these undef values yourself (in a pass/fronted)?

Yes, frontend

> Can you elaborate a little on why you think "undef" is the correct value?
> Inside LLVM, undef essentially means "any value we choose". The language
> reference has a section on this. It would be entirely correct if we emitted
> all 1s instead of all 0s for undef. If you really want it to be .bss,
> zeroinitializer seems to be the better choice.

Yes, any value would be semantically correct. What I am communicating to
LLVM is "any value will be fine here" which means that LLVM can do whatever
it wants here to achieve better performance, compile time speed, smaller
object size, or another goal that I have not thought of. And in this email
thread I am suggesting that LLVM should probably choose the smaller object
size goal in this situation, choose 0 for the value, and put it in .bss.

> Tobias
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170425/89dd08e2/attachment.html>

More information about the llvm-dev mailing list