@@ -86,13 +86,29 @@ struct MachObj
8686 OutBuffer * local_symbuf,
8787 public_symbuf,
8888 extern_symbuf;
89+
90+ OutBuffer * comdef_symbuf; // Comdef's are stored here
91+
92+ OutBuffer * indirectsymbuf1; // indirect symbol table of Symbol*'s
93+ int jumpTableSeg; // segment index for __jump_table
94+
95+ OutBuffer * indirectsymbuf2; // indirect symbol table of Symbol*'s
96+ int pointersSeg; // segment index for __pointers
97+
98+ /* If an MachObj_external_def() happens, set this to the string index,
99+ * to be added last to the symbol table.
100+ * Obviously, there can be only one.
101+ */
102+ IDXSTR extdef;
89103}
90104
91105private __gshared MachObj machobj;
92106
93107
94108enum DEST_LEN = (IDMAX + IDOHD + 1 );
95109
110+ struct Comdef { Symbol* sym; targ_size_t size; int count; }
111+
96112/* *****************************************
97113 */
98114
@@ -152,24 +168,6 @@ private void reset_symbols(OutBuffer* buf)
152168 symbol_reset(* p[i]);
153169}
154170
155- __gshared
156- {
157-
158- struct Comdef { Symbol* sym; targ_size_t size; int count; }
159- private OutBuffer * comdef_symbuf; // Comdef's are stored here
160-
161- private OutBuffer * indirectsymbuf1; // indirect symbol table of Symbol*'s
162- private int jumpTableSeg; // segment index for __jump_table
163-
164- private OutBuffer * indirectsymbuf2; // indirect symbol table of Symbol*'s
165- private int pointersSeg; // segment index for __pointers
166-
167- /* If an MachObj_external_def() happens, set this to the string index,
168- * to be added last to the symbol table.
169- * Obviously, there can be only one.
170- */
171- private IDXSTR extdef;
172- }
173171
174172// Each compiler segment is a section
175173// Predefined compiler segments CODE,DATA,CDATA,UDATA map to indexes
@@ -449,24 +447,24 @@ Obj MachObj_init(OutBuffer* objbuf, const(char)* filename, const(char)* csegname
449447 machobj.extern_symbuf.reserve ((Symbol* ).sizeof * SYM_TAB_INIT );
450448 }
451449
452- if (! comdef_symbuf)
450+ if (! machobj. comdef_symbuf)
453451 {
454- comdef_symbuf = cast (OutBuffer * ) calloc(1 , OutBuffer .sizeof);
455- if (! comdef_symbuf)
452+ machobj. comdef_symbuf = cast (OutBuffer * ) calloc(1 , OutBuffer .sizeof);
453+ if (! machobj. comdef_symbuf)
456454 err_nomem();
457- comdef_symbuf.reserve ((Symbol* ).sizeof * SYM_TAB_INIT );
455+ machobj. comdef_symbuf.reserve ((Symbol* ).sizeof * SYM_TAB_INIT );
458456 }
459- comdef_symbuf.reset();
457+ machobj. comdef_symbuf.reset();
460458
461- extdef = 0 ;
459+ machobj. extdef = 0 ;
462460
463- if (indirectsymbuf1)
464- indirectsymbuf1.reset();
465- jumpTableSeg = 0 ;
461+ if (machobj. indirectsymbuf1)
462+ machobj. indirectsymbuf1.reset();
463+ machobj. jumpTableSeg = 0 ;
466464
467- if (indirectsymbuf2)
468- indirectsymbuf2.reset();
469- pointersSeg = 0 ;
465+ if (machobj. indirectsymbuf2)
466+ machobj. indirectsymbuf2.reset();
467+ machobj. pointersSeg = 0 ;
470468
471469 // Initialize segments for CODE, DATA, UDATA and CDATA
472470 size_t struct_section_size = I64 ? section_64.sizeof : section.sizeof;
@@ -596,9 +594,9 @@ void mach_numbersyms()
596594 n++ ;
597595 }
598596
599- dim = cast (int )(comdef_symbuf.length() / Comdef.sizeof);
597+ dim = cast (int )(machobj. comdef_symbuf.length() / Comdef.sizeof);
600598 for (int i = 0 ; i < dim; i++ )
601- { Comdef* c = (cast (Comdef* )comdef_symbuf.buf) + i;
599+ { Comdef* c = (cast (Comdef* )machobj. comdef_symbuf.buf) + i;
602600 c.sym.Sxtrnnum = n;
603601 n++ ;
604602 }
@@ -738,21 +736,21 @@ void MachObj_term(const(char)[] objfilename)
738736 * field to the symbol index in the indirect symbol table of the
739737 * start of the __pointers symbols.
740738 */
741- if (pointersSeg)
739+ if (machobj. pointersSeg)
742740 {
743- seg_data* pseg = SegData[pointersSeg];
741+ seg_data* pseg = SegData[machobj. pointersSeg];
744742 if (I64 )
745743 {
746744 section_64* psechdr = &SecHdrTab64[pseg.SDshtidx]; // corresponding section
747- psechdr.reserved1 = cast (uint )(indirectsymbuf1
748- ? indirectsymbuf1.length() / (Symbol* ).sizeof
745+ psechdr.reserved1 = cast (uint )(machobj. indirectsymbuf1
746+ ? machobj. indirectsymbuf1.length() / (Symbol* ).sizeof
749747 : 0 );
750748 }
751749 else
752750 {
753751 section* psechdr = &SecHdrTab[pseg.SDshtidx]; // corresponding section
754- psechdr.reserved1 = cast (uint )(indirectsymbuf1
755- ? indirectsymbuf1.length() / (Symbol* ).sizeof
752+ psechdr.reserved1 = cast (uint )(machobj. indirectsymbuf1
753+ ? machobj. indirectsymbuf1.length() / (Symbol* ).sizeof
756754 : 0 );
757755 }
758756 }
@@ -1375,7 +1373,7 @@ void MachObj_term(const(char)[] objfilename)
13751373 dysymtab_cmd.nextdefsym = cast (uint )(machobj.public_symbuf.length() / (Symbol* ).sizeof);
13761374 dysymtab_cmd.iundefsym = dysymtab_cmd.iextdefsym + dysymtab_cmd.nextdefsym;
13771375 int nexterns = cast (int )(machobj.extern_symbuf.length() / (Symbol* ).sizeof);
1378- int ncomdefs = cast (int )(comdef_symbuf.length() / Comdef.sizeof);
1376+ int ncomdefs = cast (int )(machobj. comdef_symbuf.length() / Comdef.sizeof);
13791377 dysymtab_cmd.nundefsym = nexterns + ncomdefs;
13801378 symtab_cmd.nsyms = dysymtab_cmd.nlocalsym +
13811379 dysymtab_cmd.nextdefsym +
@@ -1458,7 +1456,7 @@ void MachObj_term(const(char)[] objfilename)
14581456 }
14591457 }
14601458 for (int i = 0 ; i < ncomdefs; i++ )
1461- { Comdef* c = (cast (Comdef* )comdef_symbuf.buf) + i;
1459+ { Comdef* c = (cast (Comdef* )machobj. comdef_symbuf.buf) + i;
14621460 nlist_64 sym;
14631461 sym.n_strx = mach_addmangled(c.sym);
14641462 sym.n_value = c.size * c.count;
@@ -1489,10 +1487,10 @@ void MachObj_term(const(char)[] objfilename)
14891487 machobj.fobjbuf.write(&sym32, sym32.sizeof);
14901488 }
14911489 }
1492- if (extdef)
1490+ if (machobj. extdef)
14931491 {
14941492 nlist_64 sym;
1495- sym.n_strx = extdef;
1493+ sym.n_strx = machobj. extdef;
14961494 sym.n_value = 0 ;
14971495 sym.n_type = N_EXT | N_UNDF ;
14981496 sym.n_desc = 0 ;
@@ -1524,20 +1522,20 @@ void MachObj_term(const(char)[] objfilename)
15241522 // Put out indirectsym table, which is in two parts
15251523 foffset = elf_align(I64 ? 8 : 4 , foffset);
15261524 dysymtab_cmd.indirectsymoff = foffset;
1527- if (indirectsymbuf1)
1525+ if (machobj. indirectsymbuf1)
15281526 {
1529- dysymtab_cmd.nindirectsyms += indirectsymbuf1.length() / (Symbol* ).sizeof;
1527+ dysymtab_cmd.nindirectsyms += machobj. indirectsymbuf1.length() / (Symbol* ).sizeof;
15301528 for (int i = 0 ; i < dysymtab_cmd.nindirectsyms; i++ )
1531- { Symbol* s = (cast (Symbol** )indirectsymbuf1.buf)[i];
1529+ { Symbol* s = (cast (Symbol** )machobj. indirectsymbuf1.buf)[i];
15321530 machobj.fobjbuf.write32(s.Sxtrnnum);
15331531 }
15341532 }
1535- if (indirectsymbuf2)
1533+ if (machobj. indirectsymbuf2)
15361534 {
1537- int n = cast (int )(indirectsymbuf2.length() / (Symbol* ).sizeof);
1535+ int n = cast (int )(machobj. indirectsymbuf2.length() / (Symbol* ).sizeof);
15381536 dysymtab_cmd.nindirectsyms += n;
15391537 for (int i = 0 ; i < n; i++ )
1540- { Symbol* s = (cast (Symbol** )indirectsymbuf2.buf)[i];
1538+ { Symbol* s = (cast (Symbol** )machobj. indirectsymbuf2.buf)[i];
15411539 machobj.fobjbuf.write32(s.Sxtrnnum);
15421540 }
15431541 }
@@ -2408,8 +2406,8 @@ int MachObj_external_def(const(char)* name)
24082406{
24092407 // printf("MachObj_external_def('%s')\n",name);
24102408 assert (name);
2411- assert (extdef == 0 );
2412- extdef = MachObj_addstr(machobj.symtab_strings, name);
2409+ assert (machobj. extdef == 0 );
2410+ machobj. extdef = MachObj_addstr(machobj.symtab_strings, name);
24132411 return 0 ;
24142412}
24152413
@@ -2458,7 +2456,7 @@ int MachObj_common_block(Symbol* s,targ_size_t size,targ_size_t count)
24582456 comdef.sym = s;
24592457 comdef.size = size;
24602458 comdef.count = cast (int )count;
2461- comdef_symbuf.write(&comdef, (comdef).sizeof);
2459+ machobj. comdef_symbuf.write(&comdef, (comdef).sizeof);
24622460 s.Sxtrnnum = 1 ;
24632461 if (! s.Sseg)
24642462 s.Sseg = UDATA ;
@@ -2734,27 +2732,27 @@ int MachObj_reftoident(int seg, targ_size_t offset, Symbol* s, targ_size_t val,
27342732 {
27352733 if (SegData[seg].isCode() && flags & CFselfrel)
27362734 {
2737- if (! jumpTableSeg)
2735+ if (! machobj. jumpTableSeg)
27382736 {
2739- jumpTableSeg =
2737+ machobj. jumpTableSeg =
27402738 MachObj_getsegment(" __jump_table" , " __IMPORT" , 0 , S_SYMBOL_STUBS | S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS | S_ATTR_SELF_MODIFYING_CODE );
27412739 }
2742- seg_data* pseg = SegData[jumpTableSeg];
2740+ seg_data* pseg = SegData[machobj. jumpTableSeg];
27432741 if (I64 )
27442742 SecHdrTab64[pseg.SDshtidx].reserved2 = 5 ;
27452743 else
27462744 SecHdrTab[pseg.SDshtidx].reserved2 = 5 ;
27472745
2748- if (! indirectsymbuf1)
2746+ if (! machobj. indirectsymbuf1)
27492747 {
2750- indirectsymbuf1 = cast (OutBuffer * ) calloc(1 , OutBuffer .sizeof);
2751- if (! indirectsymbuf1)
2748+ machobj. indirectsymbuf1 = cast (OutBuffer * ) calloc(1 , OutBuffer .sizeof);
2749+ if (! machobj. indirectsymbuf1)
27522750 err_nomem();
27532751 }
27542752 else
27552753 { // Look through indirectsym to see if it is already there
2756- int n = cast (int )(indirectsymbuf1.length() / (Symbol* ).sizeof);
2757- Symbol** psym = cast (Symbol** )indirectsymbuf1.buf;
2754+ int n = cast (int )(machobj. indirectsymbuf1.length() / (Symbol* ).sizeof);
2755+ Symbol** psym = cast (Symbol** )machobj. indirectsymbuf1.buf;
27582756 for (int i = 0 ; i < n; i++ )
27592757 { // Linear search, pretty pathetic
27602758 if (s == psym[i])
@@ -2768,11 +2766,11 @@ int MachObj_reftoident(int seg, targ_size_t offset, Symbol* s, targ_size_t val,
27682766 static immutable char [5 ] halts = [ 0xF4 ,0xF4 ,0xF4 ,0xF4 ,0xF4 ];
27692767 pseg.SDbuf.write(halts.ptr, 5 );
27702768
2771- // Add symbol s to indirectsymbuf1
2772- indirectsymbuf1.write((&s)[0 .. 1 ]);
2769+ // Add symbol s to machobj. indirectsymbuf1
2770+ machobj. indirectsymbuf1.write((&s)[0 .. 1 ]);
27732771 L1 :
27742772 val -= offset + 4 ;
2775- MachObj_addrel(seg, offset, null , jumpTableSeg, RELrel);
2773+ MachObj_addrel(seg, offset, null , machobj. jumpTableSeg, RELrel);
27762774 }
27772775 else if (SegData[seg].isCode() &&
27782776 ! (flags & CFindirect) &&
@@ -2785,23 +2783,23 @@ int MachObj_reftoident(int seg, targ_size_t offset, Symbol* s, targ_size_t val,
27852783 else if ((flags & CFindirect) ||
27862784 SegData[seg].isCode() && ! tyfunc(s.ty()))
27872785 {
2788- if (! pointersSeg)
2786+ if (! machobj. pointersSeg)
27892787 {
2790- pointersSeg =
2788+ machobj. pointersSeg =
27912789 MachObj_getsegment(" __pointers" , " __IMPORT" , 0 , S_NON_LAZY_SYMBOL_POINTERS );
27922790 }
2793- seg_data* pseg = SegData[pointersSeg];
2791+ seg_data* pseg = SegData[machobj. pointersSeg];
27942792
2795- if (! indirectsymbuf2)
2793+ if (! machobj. indirectsymbuf2)
27962794 {
2797- indirectsymbuf2 = cast (OutBuffer * ) calloc(1 , OutBuffer .sizeof);
2798- if (! indirectsymbuf2)
2795+ machobj. indirectsymbuf2 = cast (OutBuffer * ) calloc(1 , OutBuffer .sizeof);
2796+ if (! machobj. indirectsymbuf2)
27992797 err_nomem();
28002798 }
28012799 else
28022800 { // Look through indirectsym to see if it is already there
2803- int n = cast (int )(indirectsymbuf2.length() / (Symbol* ).sizeof);
2804- Symbol** psym = cast (Symbol** )indirectsymbuf2.buf;
2801+ int n = cast (int )(machobj. indirectsymbuf2.length() / (Symbol* ).sizeof);
2802+ Symbol** psym = cast (Symbol** )machobj. indirectsymbuf2.buf;
28052803 for (int i = 0 ; i < n; i++ )
28062804 { // Linear search, pretty pathetic
28072805 if (s == psym[i])
@@ -2815,16 +2813,16 @@ int MachObj_reftoident(int seg, targ_size_t offset, Symbol* s, targ_size_t val,
28152813 pseg.SDbuf.writezeros(_tysize[TYnptr]);
28162814
28172815 // Add symbol s to indirectsymbuf2
2818- indirectsymbuf2.write((&s)[0 .. 1 ]);
2816+ machobj. indirectsymbuf2.write((&s)[0 .. 1 ]);
28192817
28202818 L2 :
2821- // printf("MachObj_reftoident: seg = %d, offset = x%x, s = %s, val = x%x, pointersSeg = %d\n", seg, cast(int)offset, s.Sident.ptr, cast(int)val, pointersSeg);
2819+ // printf("MachObj_reftoident: seg = %d, offset = x%x, s = %s, val = x%x, pointersSeg = %d\n", seg, cast(int)offset, s.Sident.ptr, cast(int)val, machobj. pointersSeg);
28222820 if (flags & CFindirect)
28232821 {
28242822 Relocation rel = void ;
28252823 rel.offset = offset;
28262824 rel.targsym = null ;
2827- rel.targseg = pointersSeg;
2825+ rel.targseg = machobj. pointersSeg;
28282826 rel.rtype = RELaddr;
28292827 rel.flag = 0 ;
28302828 rel.funcsym = null ;
@@ -2839,7 +2837,7 @@ int MachObj_reftoident(int seg, targ_size_t offset, Symbol* s, targ_size_t val,
28392837 pseg2.SDrel.write(&rel, rel.sizeof);
28402838 }
28412839 else
2842- MachObj_addrel(seg, offset, null , pointersSeg, RELaddr);
2840+ MachObj_addrel(seg, offset, null , machobj. pointersSeg, RELaddr);
28432841 }
28442842 else
28452843 { // val -= s.Soffset;
0 commit comments