[llvm-dev] Create the GlobalVariable which have extern in one header file (original) (raw)
Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 21 21:02:34 PST 2019
- Previous message: [llvm-dev] Create the GlobalVariable which have extern in one header file
- Next message: [llvm-dev] Create the GlobalVariable which have extern in one header file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 21 Feb 2019 at 18:42, Mustakimur Khandaker via llvm-dev <llvm-dev at lists.llvm.org> wrote:
GlobalVariable *gvardata = new GlobalVariable( M, blockItems->getType(), true, GlobalValue::CommonLinkage, blockItems, "DATATABLE"); gvardata->setAlignment(16); gvardata->setSection("datasection"); gvardata->addAttribute(llvm::Attribute::OptimizeNone);
I am not sure if I am using the correct Linkage or not. The pass has failed to complete it. Here is the runtime fault. Any guess what I am doing incorrect?
As you've guessed, it's the linkage.
"common" is the name for the C situation where multiple source files simply declare "int a;" with nothing else specified. The names get merged, and the variable gets zero-initialized by default. A "real" definition (like you're trying to provide) would take precedence over this and specify the actual data.
You almost certainly want GlobalValue::ExternalLinkage for a bog-standard global variable.
Cheers.
Tim.
- Previous message: [llvm-dev] Create the GlobalVariable which have extern in one header file
- Next message: [llvm-dev] Create the GlobalVariable which have extern in one header file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]