Creating a global variable from a struct array

I would like to create a global variable for the following struct array, h1

dhash* h1 = new dhash[10];

typedef struct dhash{
char* filenm;
dlist* llist;
}dhash;

typedef struct dlist{
int soffst;
int eoffst;
uint8_t* dptr;
}dlist;

I need to recursively allocate space for:

  1. the field llist in struct dhash which is a pointer to another struct dlist
  2. the field dptr in struct dlist

Is there an example that I can refer to ?

I tried to create a GlobalVariable using ConstantStruct::get(StructType, ArrayRef<Constant >) . I’m not sure how to get the second argument of type *ArrayRef<Constant > from the above variable h1.

ConstantStruct::get would give you a constant for the struct, while it seems that your global is just a pointer to the StructType I think.