[PATCH] D27547: Allow common linkage global var have non-zero initializer

Liu, Yaxun (Sam) via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 08:36:21 PST 2016


Good question. Thanks.

Common linkage does not have a section, so if it has non-zero value then it cannot be represented in obj file.

I am thinking to drop this patch and use weak linkage instead, because

1. they will be replaced if there is another instance when linking
2. if not referenced, they are not dropped

Any comments? Thanks.

Sam

-----Original Message-----
From: Rafael Avila de Espindola [mailto:rafael.espindola at gmail.com] 
Sent: Wednesday, December 07, 2016 9:35 PM
To: reviews+D27547+public+63a4de9a2d333423 at reviews.llvm.org; Yaxun Liu via Phabricator <reviews at reviews.llvm.org>; Liu, Yaxun (Sam) <Yaxun.Liu at amd.com>; Stellard, Thomas <Tom.Stellard at amd.com>
Cc: llvm-commits at lists.llvm.org; Ding, Wei <Wei.Ding2 at amd.com>
Subject: Re: [PATCH] D27547: Allow common linkage global var have non-zero initializer

Yaxun Liu via Phabricator via llvm-commits <llvm-commits at lists.llvm.org>
writes:

> yaxunl created this revision.
> yaxunl added a reviewer: tstellarAMD.
> yaxunl added a subscriber: llvm-commits.
> Herald added a subscriber: wdng.
>
> In C99 tentative definition of file-scope variable results in common linkage, e.g.
>
>   private char *p;
>   private char *p;
>
> which are initialized by default initializer. For pointer type global variable, the default initializer is null pointer, which does not necessarily have zero value. If a structure contains  pointer type member for which null pointer does not have zero value, the strucutre cannot be initialized with zeroinitializer.
>
> Currently IR Verifier asserts when a global variable with common linkage has an initializer which is not zeroinitializer, which it should not. This patch fixes that.

How is this represented it the object file level?

Cheers,
Rafael


More information about the llvm-commits mailing list