Segment* GetSegment (unsigned Name, unsigned char AddrSize, const char* ObjName) /* Search for a segment and return an existing one. If the segment does not ** exist, create a new one and return that. ObjName is only used for the error ** message and may be NULL if the segment is linker generated. */ { /* Try to locate the segment in the table */ Segment* S = SegFind (Name); /* If we don't have that segment already, allocate it using the type of ** the first section. */ if (S == 0) { /* Create a new segment */ S = NewSegment (Name, AddrSize); } else { /* Check if the existing segment has the requested address size */ if (S->AddrSize != AddrSize) { /* Allow an empty object name */ if (ObjName == 0) { ObjName = "[linker generated]"; } Error ("Module '%s': Type mismatch for segment '%s'", ObjName, GetString (Name)); } } /* Return the segment */ return S; }
static SegDesc* NewSegDesc (unsigned Name) /* Create a segment descriptor */ { Segment* Seg; /* Check for duplicate names */ SegDesc* S = CfgFindSegDesc (Name); if (S) { CfgError ("Segment `%s' defined twice", GetString (Name)); } /* Search for the actual segment in the input files. The function may * return NULL (no such segment), this is checked later. */ Seg = SegFind (Name); /* Allocate memory */ S = xmalloc (sizeof (SegDesc)); /* Initialize the fields */ S->Name = Name; S->Next = 0; S->Seg = Seg; S->Attr = 0; S->Flags = 0; S->Align = 0; /* ...and return it */ return S; }