home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / 68kdisassem / patch1 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  43.9 KB

  1. From: seismo!mcvax!daimi!pederch (Peder Chr. N|rgaard)
  2. Subject: Patches to make MC68000 disassembler work on SUN UNIX
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 4, Issue 39
  7. Submitted by: seismo!mcvax!daimi!pederch (Peder Chr. N|rgaard)
  8.  
  9.  
  10. Below follow diffs to the original posting of 'unc' to make it run
  11. on SUN Unix, a 4.2BSD Unix for the M68000. The diff set it a small
  12. subset of the diff set to the version I work at currently, for 
  13. reasons to be explained below. It is the smallest possible diff
  14. set that makes it possible to compile and run the 'unc' without
  15. running headlong into troubles.
  16.  
  17. There are several problems with using the 'unc' on a SUN Unix
  18. system; I list the two most severe ones. They both
  19. have to do with some assumption made by to program, and not
  20. holding on SUN Unix.
  21.  
  22. The problems means that the program is great for disassembling
  23. most object files, including the standard libraries, but it
  24. cannot in general search for object modules in stripped exe-
  25. cutables binaries.
  26.  
  27. 1) SUN Unix (and, I believe, all 4.2bsd ports of unix) uses
  28. a new kind of libraries, called 'ranlib's, random libraries.
  29. These libraries start with an index of entry points-to-module
  30. relations. Therefore the libraries do not have to be sorted
  31. with 'lorder' - and they are not! This means that the logic
  32. of 'firstfile' in libmtch.c, routine lscan, just doesn't work.
  33.  
  34. As you can imagine, it is not reasonable just to remove that
  35. logic and accept a search time of O(size-of-mainfile*count-of-
  36. modules); the standard C library of SUN Unix holds almost 300
  37. modules, and it would take days to search it in the brute force
  38. way of the distributed 'unc'. This is, however, what the cur-
  39. rent program does.
  40.  
  41. The solution is to optimize the search. I have more or less
  42. implemented a quite efficient solution, which I am willing
  43. to distribute when it is completely tested. I don't send it
  44. with this set of diffs, as I don't think this problem has
  45. very much to do with SUN Unix; it is a general improvement
  46. of the program.
  47.  
  48. 2) SUN Unix library modules are very ingeniously build.
  49. They include horrible things like 
  50.     - undefined symbols not referred to in module
  51.       (to provoke a certain load sequence, I believe)
  52.     - self-modifying code in the data segment (substi-
  53.       tution of floating point arithmetic depending
  54.       on hardware configuration, I think)
  55.     - data constants in text segment 
  56. and a lot of other stuff. And these things are present in
  57. all programs, provoked by the reference from 'printf' to
  58. the floating point code.
  59.  
  60. I have 'solved' the last problem; the diffs to 'iset.c'
  61. contain the necessary logic. The other problems can only
  62. be solved by relaxing the assumption that everything in
  63. the text module is code, until explicitly disproved.
  64. I have a lot of ideas on better assumptions, but none
  65. which are easy to implement as changes to the program.
  66.  
  67. The diffs follows: They are relative to the original 
  68. posting, and they are made by program 'diff' on the two
  69. directories,
  70.         [ the diffs were originally standard diff,
  71. I converted them to context diff format - patch likes
  72. context diffs better if minor changes have been made
  73. to the files           - moderator ]
  74.                                       I have used Larry
  75. Walls 'patch' program to verify the diffs, and the result
  76. is compilable and runnable apart from the problems described
  77. above.
  78.  
  79. Oh, one last thing. I have included a modification of the
  80. file 'doc' to put it into the on-line manual format. The SUN
  81. Unix system doesn't have whatever nroff macro package are
  82. used for that file.
  83.  
  84. Yours Truly
  85. Peder Chr. N|rgaard            pederch@daimi.UUCP
  86. ---------------------------------------------------------
  87.  
  88. diff -c1 ../temp2/alloc.c ./alloc.c
  89. *** ../temp2/alloc.c    Thu Mar 27 09:47:34 1986
  90. --- ./alloc.c    Thu Mar 27 09:48:21 1986
  91. ***************
  92. *** 161,164
  93.       
  94. -     seg += TEXT - RTEXT;
  95. -     
  96.       /*
  97.  
  98. --- 161,162 -----
  99.       
  100.       /*
  101. ***************
  102. *** 184,186
  103.       res->s_value = pos;
  104. !     if  (seg == TEXT)  {
  105.           t_entry    tent;
  106.  
  107. --- 182,184 -----
  108.       res->s_value = pos;
  109. !     if  (seg == N_TEXT)  {
  110.           t_entry    tent;
  111. ***************
  112. *** 191,193
  113.       }
  114. !     else  if  (seg == DATA  ||  seg == BSS)  {
  115.           d_entry dent;
  116.  
  117. --- 189,191 -----
  118.       }
  119. !     else  if  (seg == N_DATA  ||  seg == N_BSS)  {
  120.           d_entry dent;
  121. ***************
  122. *** 216,218
  123.           tent.t_lab = inventsymb("TS");
  124. !         tent.t_lab->s_type = TEXT;
  125.           tent.t_lab->s_value = loc;
  126.  
  127. --- 214,216 -----
  128.           tent.t_lab = inventsymb("TS");
  129. !         tent.t_lab->s_type = N_TEXT;
  130.           tent.t_lab->s_value = loc;
  131. ***************
  132. *** 273,275
  133.               ds = inventsymb("BS");
  134. !             ds->s_type = BSS;
  135.           }
  136.  
  137. --- 271,273 -----
  138.               ds = inventsymb("BS");
  139. !             ds->s_type = N_BSS;
  140.           }
  141. ***************
  142. *** 277,279
  143.               ds = inventsymb("DS");
  144. !             ds->s_type = DATA;
  145.           }
  146.  
  147. --- 275,277 -----
  148.               ds = inventsymb("DS");
  149. !             ds->s_type = N_DATA;
  150.           }
  151. diff -c1 ../temp2/doc ./doc
  152. *** ../temp2/doc    Thu Mar 27 09:47:34 1986
  153. --- ./doc    Thu Mar 27 09:48:28 1986
  154. ***************
  155. *** 1,11
  156. ! .\"/*%    nroff -cm -rL72 %|epson|spr -f plain.a -h uncdoc -w
  157. ! .nr Hb 7
  158. ! .nr Hs 3
  159. ! .ds HF 3 3 3 3 3 3 3
  160. ! .nr Hu 5
  161. ! .nr Hc 1
  162. ! .SA 1
  163. ! .PH "''A Disassembler''"
  164. ! .PF "'Issue %I%'- Page \\\\nP -'%G%'"
  165. ! .H 1 "Introduction"
  166.   This document describes the first release of a disassembler for UNIX
  167.  
  168. --- 1,16 -----
  169. ! .\"unc.1, from John Collins
  170. ! .TH UNC 1 "1 November 1985"
  171. ! .SH NAME
  172. ! unc \- a M68000 disassembler
  173. ! .SH SYNOPSIS
  174. ! .B /usr/local/unc
  175. ! [ \fB\-o\fP \fIfilename\fP ]
  176. ! [ \fB\-t\fP \fIprefix\fP ]
  177. ! [ \fB\-a\fP ]
  178. ! [ \fB\-s\fP ]
  179. ! [ \fB\-v\fP ]
  180. ! mainfile
  181. ! [ lib-or-obj \fB\|.\|.\|.\fP ]
  182. ! .SH DESCRIPTION
  183. ! .LP
  184.   This document describes the first release of a disassembler for UNIX
  185. ***************
  186. *** 13,16
  187.   The key features are:
  188. ! .AL
  189. ! .LI
  190.   For object files the output can be assembled to generate the same
  191.  
  192. --- 18,21 -----
  193.   The key features are:
  194. ! .RS
  195. ! .PP
  196.   For object files the output can be assembled to generate the same
  197. ***************
  198. *** 18,20
  199.   input.
  200. ! .LI
  201.   For stripped executable files object modules and libraries may be scanned,
  202.  
  203. --- 23,25 -----
  204.   input.
  205. ! .PP
  206.   For stripped executable files object modules and libraries may be scanned,
  207. ***************
  208. *** 22,24
  209.   inserted into the output.
  210. ! .LI
  211.   An option is available to convert most non-global names into local symbols,
  212.  
  213. --- 27,29 -----
  214.   inserted into the output.
  215. ! .PP
  216.   An option is available to convert most non-global names into local symbols,
  217. ***************
  218. *** 25,27
  219.   which cuts down the symbols in the generated assembler file.
  220. ! .LI
  221.   The disassembler copes reasonably with modules merged with the
  222.  
  223. --- 30,32 -----
  224.   which cuts down the symbols in the generated assembler file.
  225. ! .PP
  226.   The disassembler copes reasonably with modules merged with the
  227. ***************
  228. *** 31,34
  229.   generating a warning message as to the number of modules involved.
  230. ! .LE
  231. ! .P
  232.   At present this is available for certain Motorola 68000 ports of UNIX
  233.  
  234. --- 36,39 -----
  235.   generating a warning message as to the number of modules involved.
  236. ! .RE
  237. ! .PP
  238.   At present this is available for certain Motorola 68000 ports of UNIX
  239. ***************
  240. *** 35,38
  241.   System III and System V. Dependencies on
  242. ! .AL a
  243. ! .LI
  244.   Instruction set.
  245.  
  246. --- 40,43 -----
  247.   System III and System V. Dependencies on
  248. ! .TP
  249. ! (1)
  250.   Instruction set.
  251. ***************
  252. *** 38,40
  253.   Instruction set.
  254. ! .LI
  255.   Object module format.
  256.  
  257. --- 43,46 -----
  258.   Instruction set.
  259. ! .TP
  260. ! (2)
  261.   Object module format.
  262. ***************
  263. *** 40,42
  264.   Object module format.
  265. ! .LI
  266.   Library module format.
  267.  
  268. --- 46,49 -----
  269.   Object module format.
  270. ! .TP
  271. ! (3)
  272.   Library module format.
  273. ***************
  274. *** 42,44
  275.   Library module format.
  276. ! .LI
  277.   Assembler output format.
  278.  
  279. --- 49,52 -----
  280.   Library module format.
  281. ! .TP
  282. ! (4)
  283.   Assembler output format.
  284. ***************
  285. *** 44,47
  286.   Assembler output format.
  287. ! .LE
  288. ! .P
  289.   are hopefully sufficiently localised to make the product useful as a
  290.  
  291. --- 52,54 -----
  292.   Assembler output format.
  293. ! .PP
  294.   are hopefully sufficiently localised to make the product useful as a
  295. ***************
  296. *** 48,50
  297.   basis for other disassemblers for other versions of UNIX.
  298. ! .P
  299.   The product is thus distributed in source form at present.
  300.  
  301. --- 55,57 -----
  302.   basis for other disassemblers for other versions of UNIX.
  303. ! .PP
  304.   The product is thus distributed in source form at present.
  305. ***************
  306. *** 50,57
  307.   The product is thus distributed in source form at present.
  308. ! .H 1 "Use"
  309. ! The disassembler is run by entering:
  310. ! .DS I
  311. ! unc mainfile lib1 lib2 ...
  312. ! .DE
  313. ! .P
  314.   The first named file is the file to be disassembled, which should be
  315.  
  316. --- 57,59 -----
  317.   The product is thus distributed in source form at present.
  318. ! .SH USE
  319.   The first named file is the file to be disassembled, which should be
  320. ***************
  321. *** 60,62
  322.   parenthesis notation, thus:
  323. ! .DS I
  324.   unc '/lib/libc.a(printf.o)'
  325.  
  326. --- 62,64 -----
  327.   parenthesis notation, thus:
  328. ! .RS
  329.   unc '/lib/libc.a(printf.o)'
  330. ***************
  331. *** 62,65
  332.   unc '/lib/libc.a(printf.o)'
  333. ! .DE
  334. ! .P
  335.   It is usually necessary to escape the arguments in this case to prevent
  336.  
  337. --- 64,66 -----
  338.   unc '/lib/libc.a(printf.o)'
  339. ! .RE
  340.   It is usually necessary to escape the arguments in this case to prevent
  341. ***************
  342. *** 72,74
  343.   thus
  344. ! .DS I
  345.   unc '-lc(printf.o)'
  346.  
  347. --- 73,76 -----
  348.   thus
  349. ! .RS
  350. ! .nf
  351.   unc '-lc(printf.o)'
  352. ***************
  353. *** 75,78
  354.   unc '-lcurses(wmove.o)'
  355. ! .DE
  356. ! .P
  357.   As an additional facility, the list of directories searched for
  358.  
  359. --- 77,80 -----
  360.   unc '-lcurses(wmove.o)'
  361. ! .fi
  362. ! .RE
  363.   As an additional facility, the list of directories searched for
  364. ***************
  365. *** 83,85
  366.   variable, and of course defaults to
  367. ! .DS I
  368.   LDPATH=/lib:/usr/lib
  369.  
  370. --- 85,87 -----
  371.   variable, and of course defaults to
  372. ! .RS
  373.   LDPATH=/lib:/usr/lib
  374. ***************
  375. *** 85,88
  376.   LDPATH=/lib:/usr/lib
  377. ! .DE
  378. ! .P
  379.   As a further facility, the insertion of
  380.  
  381. --- 87,89 -----
  382.   LDPATH=/lib:/usr/lib
  383. ! .RE
  384.   As a further facility, the insertion of
  385. ***************
  386. *** 96,98
  387.   then the command
  388. ! .DS I
  389.   unc -Lcrt0.o
  390.  
  391. --- 97,99 -----
  392.   then the command
  393. ! .RS
  394.   unc -Lcrt0.o
  395. ***************
  396. *** 98,101
  397.   unc -Lcrt0.o
  398. ! .DE
  399. ! .P
  400.   should have the desired effect.
  401.  
  402. --- 99,101 -----
  403.   unc -Lcrt0.o
  404. ! .RE
  405.   should have the desired effect.
  406. ***************
  407. *** 101,103
  408.   should have the desired effect.
  409. ! .P
  410.   Second and subsequent file arguments are only referenced for stripped
  411.  
  412. --- 101,103 -----
  413.   should have the desired effect.
  414. ! .PP
  415.   Second and subsequent file arguments are only referenced for stripped
  416. ***************
  417. *** 106,108
  418.   files, thus:
  419. ! .DS I
  420.   unc strippedfile -Lcrt0.o -lcurses -ltermcap '-lm(sqrt.o)' -lc
  421.  
  422. --- 106,108 -----
  423.   files, thus:
  424. ! .RS
  425.   unc strippedfile -Lcrt0.o -lcurses -ltermcap '-lm(sqrt.o)' -lc
  426. ***************
  427. *** 108,111
  428.   unc strippedfile -Lcrt0.o -lcurses -ltermcap '-lm(sqrt.o)' -lc
  429. ! .DE
  430. ! .P
  431.   It is advisable to make some effort to put the libraries to be searched
  432.  
  433. --- 108,110 -----
  434.   unc strippedfile -Lcrt0.o -lcurses -ltermcap '-lm(sqrt.o)' -lc
  435. ! .RE
  436.   It is advisable to make some effort to put the libraries to be searched
  437. ***************
  438. *** 116,118
  439.   is confused by object modules which are very nearly similar.
  440. ! .H 1 "Additional options"
  441.   The following options are available to modify the behaviour of the
  442.  
  443. --- 115,117 -----
  444.   is confused by object modules which are very nearly similar.
  445. ! .SH OPTIONS
  446.   The following options are available to modify the behaviour of the
  447. ***************
  448. *** 119,122
  449.   disassembler.
  450. ! .VL 15 2
  451. ! .LI "-o file"
  452.   Causes output to be sent to the specified file instead of the standard
  453.  
  454. --- 118,121 -----
  455.   disassembler.
  456. ! .TP
  457. ! .BI \-o " file"
  458.   Causes output to be sent to the specified file instead of the standard
  459. ***************
  460. *** 123,125
  461.   output.
  462. ! .LI "-t prefix"
  463.   Causes temporary files to be created with the given prefix. The default
  464.  
  465. --- 122,125 -----
  466.   output.
  467. ! .TP
  468. ! .BI \-t " prefix"
  469.   Causes temporary files to be created with the given prefix. The default
  470. ***************
  471. *** 134,136
  472.   complete map of the text and data segments is generated.
  473. ! .LI "-a"
  474.   Suppresses the generation of non-global absolute symbols from the
  475.  
  476. --- 134,137 -----
  477.   complete map of the text and data segments is generated.
  478. ! .TP
  479. ! .B \-a
  480.   Suppresses the generation of non-global absolute symbols from the
  481. ***************
  482. *** 139,141
  483.   producing as nearly identical output as possible to the original source.
  484. ! .LI "-s"
  485.   Causes an additional scan to take place where all possible labels are
  486.  
  487. --- 140,143 -----
  488.   producing as nearly identical output as possible to the original source.
  489. ! .TP
  490. ! .B \-s
  491.   Causes an additional scan to take place where all possible labels are
  492. ***************
  493. *** 143,145
  494.   ascending order, starting at 1.
  495. ! .LI "-v"
  496.   Causes a blow-by-blow account of activities to be output on the standard
  497.  
  498. --- 145,148 -----
  499.   ascending order, starting at 1.
  500. ! .TP
  501. ! .B \-v
  502.   Causes a blow-by-blow account of activities to be output on the standard
  503. ***************
  504. *** 146,149
  505.   error.
  506. ! .LE
  507. ! .H 1 "Diagnostics etc"
  508.   Truncated or garbled object and library files usually cause processing
  509.  
  510. --- 149,151 -----
  511.   error.
  512. ! .SH DIAGNOSTICS
  513.   Truncated or garbled object and library files usually cause processing
  514. ***************
  515. *** 150,152
  516.   to stop with an explanatory message.
  517. ! .P
  518.   The only other kinds of message are some passing warnings concerning
  519.  
  520. --- 152,154 -----
  521.   to stop with an explanatory message.
  522. ! .PP
  523.   The only other kinds of message are some passing warnings concerning
  524. ***************
  525. *** 154,156
  526.   or the relocation of overlapping fields. Occasionally a message
  527. ! .DS I
  528.   Library clash: message
  529.  
  530. --- 156,158 -----
  531.   or the relocation of overlapping fields. Occasionally a message
  532. ! .RS
  533.   Library clash: message
  534. ***************
  535. *** 156,159
  536.   Library clash: message
  537. ! .DE
  538. ! .P
  539.   may appear and processing cease. This message is found where at a late
  540.  
  541. --- 158,160 -----
  542.   Library clash: message
  543. ! .RE
  544.   may appear and processing cease. This message is found where at a late
  545. ***************
  546. *** 163,165
  547.   to the program which members to take in which order.
  548. ! .H 1 "Future development"
  549.   In the future it is hoped to devise ways of making the disassembler
  550.  
  551. --- 164,166 -----
  552.   to the program which members to take in which order.
  553. ! .SH FUTURE DEVELOPMENT
  554.   In the future it is hoped to devise ways of making the disassembler
  555. ***************
  556. *** 168,170
  557.   after the Common Object Format becomes more standard.
  558. ! .P
  559.   In the long term it would be desirable and useful to enhance the product
  560.  
  561. --- 169,171 -----
  562.   after the Common Object Format becomes more standard.
  563. ! .PP
  564.   In the long term it would be desirable and useful to enhance the product
  565. ***************
  566. *** 172,175
  567.   the process are seen as follows:
  568. ! .AL
  569. ! .LI
  570.   Better identification of basic blocks in the code. Switch statements are
  571.  
  572. --- 173,176 -----
  573.   the process are seen as follows:
  574. ! .TP
  575. ! (1)
  576.   Better identification of basic blocks in the code. Switch statements are
  577. ***************
  578. *** 176,178
  579.   a major problem here, as are constant data held in the text segment.
  580. ! .LI
  581.   Marrying of data to the corresponding text. It is in various places hard
  582.  
  583. --- 177,180 -----
  584.   a major problem here, as are constant data held in the text segment.
  585. ! .TP
  586. ! (2)
  587.   Marrying of data to the corresponding text. It is in various places hard
  588. ***************
  589. *** 181,183
  590.   is part of the problem of identifying basic blocks.
  591. ! .LI
  592.   Compilation of header files to work out structure references within the
  593.  
  594. --- 183,186 -----
  595.   is part of the problem of identifying basic blocks.
  596. ! .TP
  597. ! (3)
  598.   Compilation of header files to work out structure references within the
  599. ***************
  600. *** 184,187
  601.   text. At this stage some interaction may be needed.
  602. ! .LE
  603. ! .P
  604.   Meanwhile the product is one which is a useful tool to the author in its
  605.  
  606. --- 187,189 -----
  607.   text. At this stage some interaction may be needed.
  608. ! .PP
  609.   Meanwhile the product is one which is a useful tool to the author in its
  610. diff -c1 ../temp2/heur.c ./heur.c
  611. *** ../temp2/heur.c    Thu Mar 27 09:47:35 1986
  612. --- ./heur.c    Thu Mar 27 09:48:39 1986
  613. ***************
  614. *** 278,280
  615.                   ds = inventsymb("BS");
  616. !                 ds->s_type = BSS;
  617.               }
  618.  
  619. --- 278,280 -----
  620.                   ds = inventsymb("BS");
  621. !                 ds->s_type = N_BSS;
  622.               }
  623. ***************
  624. *** 282,284
  625.                   ds = inventsymb("DS");
  626. !                 ds->s_type = DATA;
  627.               }
  628.  
  629. --- 282,284 -----
  630.                   ds = inventsymb("DS");
  631. !                 ds->s_type = N_DATA;
  632.               }
  633. ***************
  634. *** 388,390
  635.       
  636. !     for  (pos = 0;  pos < endt;)  {
  637.           gette(&mainfile, pos, &tent);
  638.  
  639. --- 388,390 -----
  640.       
  641. !     for  (pos = mainfile.ef_tbase;  pos < endt;)  {
  642.           gette(&mainfile, pos, &tent);
  643. diff -c1 ../temp2/iset.c ./iset.c
  644. *** ../temp2/iset.c    Thu Mar 27 09:47:35 1986
  645. --- ./iset.c    Thu Mar 27 09:48:46 1986
  646. ***************
  647. *** 240,241
  648.       }
  649.       if  ((tc & 0xff00) == 0x6000)
  650.  
  651. --- 240,245 -----
  652.       }
  653. +     if ( dest < mainfile.ef_tbase 
  654. +         || dest >= mainfile.ef_tbase+mainfile.ef_tsize 
  655. +         || (dest & 1) != 0 )
  656. +         return 0;        /* Illegal branch destination */
  657.       if  ((tc & 0xff00) == 0x6000)
  658. ***************
  659. *** 247,249
  660.   
  661. !     te->t_relsymb = textlab(dest, pos);
  662.       return    res;
  663.  
  664. --- 251,256 -----
  665.   
  666. !     if ( (te->t_relsymb = textlab(dest, pos)) == NULL ) {
  667. !         te->t_bchtyp = T_NOBR;/* Branch to a continuation */
  668. !         return 0;
  669. !     }
  670.       return    res;
  671. ***************
  672. *** 257,258
  673.       t_entry    nextl;
  674.       
  675.  
  676. --- 264,266 -----
  677.       t_entry    nextl;
  678. +     long dest;
  679.       
  680. ***************
  681. *** 262,264
  682.           if  (nextl.t_relsymb == NULL)  {
  683. !             nextl.t_relsymb = textlab(gettw(&mainfile, pos+2, R_LONG), pos);
  684.               putte(&mainfile, pos+2, &nextl);
  685.  
  686. --- 270,278 -----
  687.           if  (nextl.t_relsymb == NULL)  {
  688. !             dest = gettw(&mainfile, pos + 2, R_LONG );
  689. !             if ( dest < mainfile.ef_tbase
  690. !                 || dest >= mainfile.ef_tbase+mainfile.ef_tsize
  691. !                 || (dest & 1) != 0 )
  692. !                 return 0;    /* Illegal branch destination */
  693. !             if ( ( nextl.t_relsymb = textlab(dest, pos) ) == NULL )
  694. !             return 0;    /* Branch to a continuation */
  695.               putte(&mainfile, pos+2, &nextl);
  696. ***************
  697. *** 995,997
  698.           te->t_type = T_UNKNOWN;
  699. !         te->t_bchtype = T_NOBR;
  700.       }
  701.  
  702. --- 1009,1011 -----
  703.           te->t_type = T_UNKNOWN;
  704. !         te->t_bchtyp = T_NOBR;
  705.       }
  706. diff -c1 ../temp2/libmtch.c ./libmtch.c
  707. *** ../temp2/libmtch.c    Thu Mar 27 09:47:36 1986
  708. --- ./libmtch.c    Thu Mar 27 09:48:54 1986
  709. ***************
  710. *** 27,28
  711.   #include <fcntl.h>
  712.   #include <a.out.h>
  713.  
  714. --- 27,29 -----
  715.   #include <fcntl.h>
  716. + #include <strings.h>
  717.   #include <a.out.h>
  718. ***************
  719. *** 32,33
  720.   
  721.   long    lseek();
  722.  
  723. --- 33,35 -----
  724.   
  725. + long    atol();
  726.   long    lseek();
  727. ***************
  728. *** 35,38
  729.   void    rrell2(), markmatch();
  730. ! char    *strchr(), *strrchr(), *strncpy(), *strcat(), *strcpy(), *malloc();
  731. ! int    matchup();
  732.   long    findstart();
  733.  
  734. --- 37,39 -----
  735.   void    rrell2(), markmatch();
  736. ! char    *malloc();
  737.   long    findstart();
  738. ***************
  739. *** 77,79
  740.       lfd->lf_offset = lfd->lf_next + sizeof(arbuf);
  741. !     lfd->lf_next = (lfd->lf_offset + arbuf.ar_size + 1) & ~1;
  742.       return    lfd->lf_offset;
  743.  
  744. --- 78,80 -----
  745.       lfd->lf_offset = lfd->lf_next + sizeof(arbuf);
  746. !     lfd->lf_next = (lfd->lf_offset + atol(arbuf.ar_size) + 1) & ~1;
  747.       return    lfd->lf_offset;
  748. ***************
  749. *** 105,107
  750.       extern    char    *getenv();
  751. !     long    magic;
  752.       struct    ar_hdr    arhdr;
  753.  
  754. --- 106,108 -----
  755.       extern    char    *getenv();
  756. !     char    magic[8];
  757.       struct    ar_hdr    arhdr;
  758. ***************
  759. *** 109,112
  760.   
  761. !     if  ((bp = strrchr(str, '(')) != NULL &&
  762. !          (ep = strrchr(str, ')')) != NULL)
  763.           *ep = *bp = '\0';
  764.  
  765. --- 110,113 -----
  766.   
  767. !     if  ((bp = rindex(str, '(')) != NULL &&
  768. !          (ep = rindex(str, ')')) != NULL)
  769.           *ep = *bp = '\0';
  770. ***************
  771. *** 123,125
  772.           do  {
  773. !             pathe = strchr(pathb, ':');
  774.               if  (*pathb == ':')
  775.  
  776. --- 124,126 -----
  777.           do  {
  778. !             pathe = index(pathb, ':');
  779.               if  (*pathb == ':')
  780. ***************
  781. *** 155,158
  782.   
  783. !     if  ((read(fd, (char *) &magic, sizeof(magic)) != sizeof(magic)  ||
  784. !         magic != ARMAG))  {
  785.           if  (ep != NULL)  {
  786.  
  787. --- 156,159 -----
  788.   
  789. !     if  (read(fd, magic, sizeof(magic)) != sizeof(magic)  ||
  790. !         strcmp(magic, ARMAG) != 0)  {
  791.           if  (ep != NULL)  {
  792. ***************
  793. *** 177,178
  794.       if  (ep != NULL)  {
  795.           currlib.lf_offset = sizeof(magic) + sizeof(struct ar_hdr);
  796.  
  797. --- 178,181 -----
  798.       if  (ep != NULL)  {
  799. +         char *cp;
  800.           currlib.lf_offset = sizeof(magic) + sizeof(struct ar_hdr);
  801. ***************
  802. *** 184,186
  803.               }
  804. !             if  (strncmp(bp+1, arhdr.ar_name, sizeof(arhdr.ar_name)) == 0)
  805.                   break;
  806.  
  807. --- 187,192 -----
  808.               }
  809. !             for ( cp = arhdr.ar_name + sizeof(arhdr.ar_name) - 1;
  810. !                 *cp == ' ';
  811. !                 cp -- ) ;
  812. !             if  (strncmp(bp+1, arhdr.ar_name, cp - arhdr.ar_name + 1) == 0)
  813.                   break;
  814. ***************
  815. *** 186,188
  816.                   break;
  817. !             currlib.lf_offset += arhdr.ar_size + sizeof(arhdr) + 1;
  818.               currlib.lf_offset &= ~ 1;
  819.  
  820. --- 192,194 -----
  821.                   break;
  822. !             currlib.lf_offset += atol(arhdr.ar_size) + sizeof(arhdr) + 1;
  823.               currlib.lf_offset &= ~ 1;
  824. ***************
  825. *** 211,213
  826.       currlib.lf_offset = sizeof(magic) + sizeof(arhdr);
  827. !     currlib.lf_next = currlib.lf_offset + arhdr.ar_size + 1;
  828.       currlib.lf_next &= ~1;
  829.  
  830. --- 217,219 -----
  831.       currlib.lf_offset = sizeof(magic) + sizeof(arhdr);
  832. !     currlib.lf_next = currlib.lf_offset + atol(arhdr.ar_size) + 1;
  833.       currlib.lf_next &= ~1;
  834. diff -c1 ../temp2/main.c ./main.c
  835. *** ../temp2/main.c    Thu Mar 27 09:47:36 1986
  836. --- ./main.c    Thu Mar 27 09:48:58 1986
  837. ***************
  838. *** 26,28
  839.   #include <stdio.h>
  840. ! #include <fcntl.h>
  841.   #include <a.out.h>
  842.  
  843. --- 26,28 -----
  844.   #include <stdio.h>
  845. ! #include <sys/file.h>
  846.   #include <a.out.h>
  847. ***************
  848. *** 28,30
  849.   #include <a.out.h>
  850. - #include <sys/var.h>
  851.   #include "unc.h"
  852.  
  853. --- 28,29 -----
  854.   #include <a.out.h>
  855.   #include "unc.h"
  856. ***************
  857. *** 38,40
  858.   
  859. - int    par_entry, par_round;    /*  68000 parameters  */
  860.   int    nmods;            /*  Number of modules it looks like  */
  861.  
  862. --- 37,38 -----
  863.   
  864.   int    nmods;            /*  Number of modules it looks like  */
  865. ***************
  866. *** 107,109
  867.       register  char    *arg;
  868. -     struct    var    vs;
  869.       
  870.  
  871. --- 105,106 -----
  872.       register  char    *arg;
  873.       
  874. ***************
  875. *** 109,114
  876.       
  877. -     uvar(&vs);
  878. -     par_entry = vs.v_ustart;
  879. -     par_round = vs.v_txtrnd - 1;
  880. -     
  881.       for  (;;)  {
  882.  
  883. --- 106,107 -----
  884.       
  885.       for  (;;)  {
  886. ***************
  887. *** 143,146
  888.   
  889. !         case  'R':
  890. !         case  'N':
  891.               if  (*arg == '\0')  {
  892.  
  893. --- 136,138 -----
  894.   
  895. !         case  't':
  896.               if  (*arg == '\0')  {
  897. ***************
  898. *** 148,150
  899.                   arg = *++av;
  900. !                 if  (arg == NULL)  {
  901.   bo:                    (void) fprintf(stderr,"Bad -%c option\n",lt);
  902.  
  903. --- 140,142 -----
  904.                   arg = *++av;
  905. !                 if  (arg == NULL) {
  906.   bo:                    (void) fprintf(stderr,"Bad -%c option\n",lt);
  907. ***************
  908. *** 151,166
  909.                       exit(1);
  910. !                 }
  911. !             }
  912. !             if  (lt == 'R')
  913. !                 par_entry = ghex(arg);
  914. !             else
  915. !                 par_round = ghex(arg) - 1;
  916. !             continue;
  917. !             
  918. !         case  't':
  919. !             if  (*arg == '\0')  {
  920. !                 cnt++;
  921. !                 arg = *++av;
  922. !                 if  (arg == NULL)
  923. !                     goto  bo;
  924.               }
  925.  
  926. --- 143,145 -----
  927.                       exit(1);
  928. !                       }
  929.               }
  930. diff -c1 ../temp2/makefile ./makefile
  931. *** ../temp2/makefile    Thu Mar 27 09:47:36 1986
  932. --- ./makefile    Thu Mar 27 09:49:02 1986
  933. ***************
  934. *** 1,2
  935. ! CFLAGS=-v -OB
  936.   OBJS=alloc.o file.o libmtch.o robj.o iset.o prin.o heur.o main.o
  937.  
  938. --- 1,2 -----
  939. ! CFLAGS=-O
  940.   OBJS=alloc.o file.o libmtch.o robj.o iset.o prin.o heur.o main.o
  941. diff -c1 ../temp2/prin.c ./prin.c
  942. *** ../temp2/prin.c    Thu Mar 27 09:47:36 1986
  943. --- ./prin.c    Thu Mar 27 09:49:08 1986
  944. ***************
  945. *** 104,106
  946.           gette(fid, tpos, &tstr);
  947. !         plabs(tstr.t_lab, TEXT);
  948.           if  (tstr.t_type == T_BEGIN)
  949.  
  950. --- 104,106 -----
  951.           gette(fid, tpos, &tstr);
  952. !         plabs(tstr.t_lab, N_TEXT);
  953.           if  (tstr.t_type == T_BEGIN)
  954. ***************
  955. *** 109,112
  956.               (void) printf("\t.long\t%s", tstr.t_relsymb->s_name);
  957. !             if  (tstr.t_relsymb->s_type!=TEXT &&
  958. !                 tstr.t_relsymb->s_type!=DATA)
  959.                   (void) printf("+0x%x", gettw(fid, tpos, R_LONG));
  960.  
  961. --- 109,112 -----
  962.               (void) printf("\t.long\t%s", tstr.t_relsymb->s_name);
  963. !             if  (tstr.t_relsymb->s_type!=N_TEXT &&
  964. !                 tstr.t_relsymb->s_type!=N_DATA)
  965.                   (void) printf("+0x%x", gettw(fid, tpos, R_LONG));
  966. ***************
  967. *** 125,127
  968.       gette(fid, tpos, &tstr);
  969. !     plabs(tstr.t_lab, TEXT);
  970.   }
  971.  
  972. --- 125,127 -----
  973.       gette(fid, tpos, &tstr);
  974. !     plabs(tstr.t_lab, N_TEXT);
  975.   }
  976. ***************
  977. *** 150,152
  978.           getde(fid, dpos, &dstr);
  979. !         plabs(dstr.d_lab, DATA);
  980.               
  981.  
  982. --- 150,152 -----
  983.           getde(fid, dpos, &dstr);
  984. !         plabs(dstr.d_lab, N_DATA);
  985.               
  986. ***************
  987. *** 270,272
  988.       getde(fid, dpos, &dstr);
  989. !     plabs(dstr.d_lab, DATA);
  990.   }
  991.  
  992. --- 270,272 -----
  993.       getde(fid, dpos, &dstr);
  994. !     plabs(dstr.d_lab, N_DATA);
  995.   }
  996. ***************
  997. *** 284,286
  998.           getde(fid, bpos, &bstr);
  999. !         plabs(bstr.d_lab, BSS);
  1000.           (void) printf("\t.space\t%d\n", bstr.d_lng);
  1001.  
  1002. --- 284,286 -----
  1003.           getde(fid, bpos, &bstr);
  1004. !         plabs(bstr.d_lab, N_BSS);
  1005.           (void) printf("\t.space\t%d\n", bstr.d_lng);
  1006. ***************
  1007. *** 290,292
  1008.       getde(fid, endb, &bstr);
  1009. !     plabs(bstr.d_lab, BSS);
  1010. ! }
  1011.  
  1012. --- 290,293 -----
  1013.       getde(fid, endb, &bstr);
  1014. !     plabs(bstr.d_lab, N_BSS);
  1015. !       }
  1016. diff -c1 ../temp2/robj.c ./robj.c
  1017. *** ../temp2/robj.c    Thu Mar 27 09:47:36 1986
  1018. --- ./robj.c    Thu Mar 27 09:49:16 1986
  1019. ***************
  1020. *** 47,48
  1021.   
  1022.   #define    DBSIZE    100
  1023.  
  1024. --- 47,50 -----
  1025.   
  1026. + #define RWORD 1
  1027. + #define RLONG 2
  1028.   #define    DBSIZE    100
  1029. ***************
  1030. *** 60,62
  1031.       t_entry        tstr;
  1032. !     struct    bhdr    filhdr;
  1033.       register  long    size;
  1034.  
  1035. --- 62,64 -----
  1036.       t_entry        tstr;
  1037. !     struct    exec    filhdr;
  1038.       register  long    size;
  1039. ***************
  1040. *** 96,98
  1041.   
  1042. !     if  (filhdr.fmagic != FMAGIC  &&  filhdr.fmagic != NMAGIC)
  1043.           return    0;
  1044.  
  1045. --- 98,100 -----
  1046.   
  1047. !     if ( N_BADMAG( filhdr ) )
  1048.           return    0;
  1049. ***************
  1050. *** 99,102
  1051.   
  1052. !     /*
  1053. !      *    Warn user if entry point does not tie up.
  1054.        */
  1055.  
  1056. --- 101,109 -----
  1057.   
  1058. !     /* I am not at all sure that this setup is correct
  1059. !      * but my SUN UNIX manual (version 1.2) is VERY unclear
  1060. !      * about the interpretation of the bases of relocatable
  1061. !      * files. This, however seems to work for executable
  1062. !      * binaries (ZMAGIC) and relocatable .o files (OMAGIC).
  1063. !      * I have not found any NMAGIC files on my system, so
  1064. !      * it is not likely to work for such ones.
  1065.        */
  1066. ***************
  1067. *** 102,106
  1068.        */
  1069. !     
  1070. !     if  (filhdr.entry != par_entry)
  1071. !         (void) fprintf(stderr, "Warning: File has -R%X\n", filhdr.entry);
  1072.   
  1073.  
  1074. --- 109,119 -----
  1075.        */
  1076. !     outf->ef_entry = filhdr.a_entry;
  1077. !     outf->ef_tbase = 
  1078. !         (filhdr.a_magic==OMAGIC) ? 0 : SEGSIZ;
  1079. !     outf->ef_dbase =
  1080. !         (filhdr.a_magic==OMAGIC)
  1081. !         ? filhdr.a_text
  1082. !         : (SEGSIZ+((SEGSIZ+filhdr.a_text-1) & ~(SEGSIZ-1)));
  1083. !     outf->ef_bbase = outf->ef_dbase + filhdr.a_data;
  1084. !     outf->ef_end = outf->ef_bbase + filhdr.a_bss;
  1085.   
  1086. ***************
  1087. *** 106,120
  1088.   
  1089. !     outf->ef_entry = filhdr.entry;
  1090. !     outf->ef_tbase = filhdr.entry;
  1091. !     outf->ef_dbase = filhdr.tsize + filhdr.entry;
  1092. !     if  (filhdr.fmagic == NMAGIC)
  1093. !         outf->ef_dbase = (outf->ef_dbase + par_round) & (~par_round);
  1094. !     outf->ef_bbase = outf->ef_dbase + filhdr.dsize;
  1095. !     outf->ef_end = outf->ef_bbase + filhdr.bsize;
  1096. !     outf->ef_tsize = filhdr.tsize;
  1097. !     outf->ef_dsize = filhdr.dsize;
  1098. !     outf->ef_bsize = filhdr.bsize;
  1099.       
  1100.  
  1101. --- 119,123 -----
  1102.   
  1103. !     outf->ef_tsize = filhdr.a_text;
  1104. !     outf->ef_dsize = filhdr.a_data;
  1105. !     outf->ef_bsize = filhdr.a_bss;
  1106.       
  1107. ***************
  1108. *** 120,122
  1109.       
  1110. !     (void) lseek(inf, offset + TEXTPOS, 0);
  1111.       
  1112.  
  1113. --- 123,125 -----
  1114.       
  1115. !     (void) lseek(inf, offset + N_TXTOFF(filhdr), 0);
  1116.       
  1117. ***************
  1118. *** 154,156
  1119.       d_entry        dstr;
  1120. !     struct    bhdr    filhdr;
  1121.       register  long    size;
  1122.  
  1123. --- 157,159 -----
  1124.       d_entry        dstr;
  1125. !     struct    exec    filhdr;
  1126.       register  long    size;
  1127. ***************
  1128. *** 179,181
  1129.   
  1130. !     (void) lseek(inf, offset + DATAPOS, 0);
  1131.       
  1132.  
  1133. --- 182,184 -----
  1134.   
  1135. !     (void) lseek(inf, offset + N_TXTOFF(filhdr) + filhdr.a_text, 0);
  1136.       
  1137. ***************
  1138. *** 220,221
  1139.   {
  1140.       register  symbol  csym;
  1141.  
  1142. --- 223,225 -----
  1143.   {
  1144. + #define SYMLENGTH 256
  1145.       register  symbol  csym;
  1146. ***************
  1147. *** 221,224
  1148.       register  symbol  csym;
  1149. !     struct    bhdr    filhdr;
  1150. !     struct    sym    isym;
  1151.       register  long    size;
  1152.  
  1153. --- 225,228 -----
  1154.       register  symbol  csym;
  1155. !     struct    exec    filhdr;
  1156. !     struct    nlist    isym;
  1157.       register  long    size;
  1158. ***************
  1159. *** 224,227
  1160.       register  long    size;
  1161. !     register  int    i, l;
  1162. !     char    inbuf[SYMLENGTH+1];
  1163.   
  1164.  
  1165. --- 228,232 -----
  1166.       register  long    size;
  1167. !     unsigned long   stroff;
  1168. !     register  int    l;
  1169. !     char    inbuf[SYMLENGTH+1], *cp;
  1170.   
  1171. ***************
  1172. *** 236,239
  1173.   
  1174. !     offset += SYMPOS;
  1175. !     size = filhdr.ssize;
  1176.       if  (size <= 0)
  1177.  
  1178. --- 241,245 -----
  1179.   
  1180. !     offset += N_SYMOFF(filhdr);
  1181. !     stroff = offset + filhdr.a_syms;
  1182. !     size = filhdr.a_syms;
  1183.       if  (size <= 0)
  1184. ***************
  1185. *** 245,247
  1186.   
  1187. !     l = size / (sizeof(struct sym) + 4);
  1188.       if  (l <= 0)
  1189.  
  1190. --- 251,253 -----
  1191.   
  1192. !     l = size / (sizeof(struct nlist) + 4);
  1193.       if  (l <= 0)
  1194. ***************
  1195. *** 256,258
  1196.       
  1197. !     while  (size > sizeof(struct sym))  {
  1198.           (void) lseek(inf, offset, 0);
  1199.  
  1200. --- 262,264 -----
  1201.       
  1202. !     while  (size > 0)  {
  1203.           (void) lseek(inf, offset, 0);
  1204. ***************
  1205. *** 261,274
  1206.           size -= sizeof(isym);
  1207. !         l = SYMLENGTH;
  1208. !         if  (l > size)
  1209. !             l = size;
  1210. !         if  (read(inf, inbuf, l) != l)
  1211. !             return    0;
  1212. !         inbuf[l] = '\0';
  1213. !         for  (i = 0; inbuf[i] != '\0';  i++)
  1214. !             ;
  1215. !         size -= i + 1;
  1216. !         offset += sizeof(isym) + i + 1;
  1217. !         csym = (*dproc)(lookup(inbuf), isym.stype, isym.svalue, outf);
  1218. !         if  (outf->ef_stcnt >= outf->ef_stmax)
  1219.               reallst(outf);
  1220.  
  1221. --- 267,281 -----
  1222.           size -= sizeof(isym);
  1223. !         offset += sizeof(isym);
  1224. !         if ( (isym.n_type & N_STAB) != 0x00 )
  1225. !             continue;/* Stab entry, not interesting for now */
  1226. !         (void) lseek(inf, stroff + isym.n_un.n_strx, 0 );
  1227. !         cp = inbuf;
  1228. !         do {
  1229. !             if ( read( inf, cp, 1 ) != 1 )/* Read symbol chars 1-by-1 */
  1230. !                 return 0;
  1231. !             if ( cp - inbuf >= SYMLENGTH )/* Check against buffer overflow */
  1232. !                 return 0;
  1233. !         } while (*cp++ != '\0');/* Terminate on null byte */
  1234. !         csym = (*dproc)(lookup(inbuf), isym.n_type, isym.n_value, outf);
  1235. !         if (outf->ef_stcnt >= outf->ef_stmax)
  1236.               reallst(outf);
  1237. ***************
  1238. *** 288,291
  1239.   {
  1240. !     struct    bhdr    filhdr;
  1241. !     struct    reloc    crel;
  1242.       t_entry    tstr;
  1243.  
  1244. --- 295,298 -----
  1245.   {
  1246. !     struct    exec    filhdr;
  1247. !     struct    relocation_info    crel;
  1248.       t_entry    tstr;
  1249. ***************
  1250. *** 303,305
  1251.           return    -1;
  1252. !     if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  1253.           return    0;
  1254.  
  1255. --- 310,312 -----
  1256.           return    -1;
  1257. !     if  (filhdr.a_trsize <= 0  &&  filhdr.a_drsize <= 0)
  1258.           return    0;
  1259. ***************
  1260. *** 306,308
  1261.   
  1262. !     size  =  filhdr.rtsize;
  1263.   
  1264.  
  1265. --- 313,315 -----
  1266.   
  1267. !     size  =  filhdr.a_trsize;
  1268.   
  1269. ***************
  1270. *** 308,311
  1271.   
  1272. !     (void) lseek(inf, RTEXTPOS + offset, 0);
  1273. !     while  (size >= sizeof(struct reloc))  {
  1274.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1275.  
  1276. --- 315,318 -----
  1277.   
  1278. !     (void) lseek(inf, N_TXTOFF(filhdr) + filhdr.a_text + filhdr.a_data + offset, 0);
  1279. !     while  (size >= sizeof(struct relocation_info))  {
  1280.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1281. ***************
  1282. *** 313,315
  1283.   
  1284. !         pos = crel.rpos + outf->ef_tbase;
  1285.           gette(outf, pos, &tstr);
  1286.  
  1287. --- 320,322 -----
  1288.   
  1289. !         pos = crel.r_address + outf->ef_tbase;
  1290.           gette(outf, pos, &tstr);
  1291. ***************
  1292. *** 315,321
  1293.           gette(outf, pos, &tstr);
  1294. !         tstr.t_reloc = crel.rsize + 1;    /*  Fiddle!  YUK!!!  */
  1295. !         tstr.t_rdisp = crel.rdisp;
  1296. !         tstr.t_rptr = crel.rsegment;
  1297. !         if  (crel.rsegment == REXT)  {
  1298. !             if  (crel.rsymbol >= outf->ef_stcnt)
  1299.                   return  -1;
  1300.  
  1301. --- 322,326 -----
  1302.           gette(outf, pos, &tstr);
  1303. !         tstr.t_reloc = crel.r_length + 1;      /*  Fiddle!  YUK!!!  */
  1304. !         if  (crel.r_extern)  {
  1305. !             if  (crel.r_symbolnum >= outf->ef_stcnt)
  1306.                   return  -1;
  1307. ***************
  1308. *** 321,324
  1309.                   return  -1;
  1310. !             tstr.t_relsymb = outf->ef_stvec[crel.rsymbol];
  1311. !             tstr.t_reldisp = gettw(outf, pos, (int)crel.rsize+1);
  1312.           }
  1313.  
  1314. --- 326,329 -----
  1315.                   return  -1;
  1316. !             tstr.t_relsymb = outf->ef_stvec[crel.r_symbolnum];
  1317. !             tstr.t_reldisp = gettw(outf, pos, (int)crel.r_length+1);
  1318.           }
  1319. ***************
  1320. *** 325,328
  1321.           else  {
  1322. !             cont = gettw(outf, pos, (int)crel.rsize+1);
  1323. !             tstr.t_relsymb = getnsymb(outf, crel.rsegment, cont);
  1324.           }
  1325.  
  1326. --- 330,333 -----
  1327.           else  {
  1328. !             cont = gettw(outf, pos, (int)crel.r_length+1);
  1329. !             tstr.t_relsymb = getnsymb(outf, crel.r_symbolnum, cont);
  1330.           }
  1331. ***************
  1332. *** 337,339
  1333.       
  1334. !     size  =  filhdr.rdsize;
  1335.       
  1336.  
  1337. --- 342,344 -----
  1338.       
  1339. !     size  =  filhdr.a_drsize;
  1340.       
  1341. ***************
  1342. *** 339,342
  1343.       
  1344. !     (void) lseek(inf, RDATAPOS + offset, 0);
  1345. !     while  (size >= sizeof(struct reloc))  {
  1346.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1347.  
  1348. --- 344,349 -----
  1349.       
  1350. !     (void) lseek(inf, 
  1351. !              N_TXTOFF(filhdr) + filhdr.a_text + filhdr.a_data 
  1352. !              + filhdr.a_trsize + offset, 0);
  1353. !     while  (size >= sizeof(struct relocation_info))  {
  1354.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1355. ***************
  1356. *** 344,346
  1357.   
  1358. !         pos = crel.rpos + outf->ef_dbase;
  1359.           getde(outf, pos, &dstr);
  1360.  
  1361. --- 351,353 -----
  1362.   
  1363. !         pos = crel.r_address + outf->ef_dbase;
  1364.           getde(outf, pos, &dstr);
  1365. ***************
  1366. *** 346,349
  1367.           getde(outf, pos, &dstr);
  1368. !         dstr.d_reloc = crel.rsize + 1;    /*  Fiddle!  YUK!!!  */
  1369. !         dstr.d_rptr = crel.rsegment;
  1370.   
  1371.  
  1372. --- 353,355 -----
  1373.           getde(outf, pos, &dstr);
  1374. !         dstr.d_reloc = crel.r_length + 1;      /*  Fiddle!  YUK!!!  */
  1375.   
  1376. ***************
  1377. *** 349,352
  1378.   
  1379. !         if  (crel.rsegment == REXT)  {
  1380. !             if  (crel.rsymbol >= outf->ef_stcnt)
  1381.                   return  -1;
  1382.  
  1383. --- 355,358 -----
  1384.   
  1385. !         if  (crel.r_extern)  {
  1386. !             if  (crel.r_symbolnum >= outf->ef_stcnt)
  1387.                   return  -1;
  1388. ***************
  1389. *** 352,355
  1390.                   return  -1;
  1391. !             dstr.d_relsymb = outf->ef_stvec[crel.rsymbol];
  1392. !             dstr.d_reldisp = getdw(outf, pos, (int)crel.rsize+1);
  1393.           }
  1394.  
  1395. --- 358,361 -----
  1396.                   return  -1;
  1397. !             dstr.d_relsymb = outf->ef_stvec[crel.r_symbolnum];
  1398. !             dstr.d_reldisp = getdw(outf, pos, (int)crel.r_length+1);
  1399.           }
  1400. ***************
  1401. *** 356,360
  1402.           else  {
  1403. !             cont = getdw(outf, pos, (int)crel.rsize+1);
  1404. !             dstr.d_relsymb = getnsymb(outf, crel.rsegment, cont);
  1405. !             if  (dstr.d_relsymb->s_type == TEXT)  {
  1406.                   gette(outf, cont, &tstr);
  1407.  
  1408. --- 362,366 -----
  1409.           else  {
  1410. !             cont = getdw(outf, pos, (int)crel.r_length+1);
  1411. !             dstr.d_relsymb = getnsymb(outf, crel.r_symbolnum, cont);
  1412. !             if  (dstr.d_relsymb->s_type == N_TEXT)  {
  1413.                   gette(outf, cont, &tstr);
  1414. ***************
  1415. *** 364,366
  1416.           }
  1417. !         switch  (crel.rsize)  {
  1418.           default:
  1419.  
  1420. --- 370,372 -----
  1421.           }
  1422. !         switch  (crel.r_length)  {
  1423.           default:
  1424. ***************
  1425. *** 403,405
  1426.       if  (!sy->s_newsym)  {
  1427. !         if  (type & EXTERN)  {
  1428.               (void) fprintf(stderr, "Duplicate symbol %s\n", sy->s_name);
  1429.  
  1430. --- 409,411 -----
  1431.       if  (!sy->s_newsym)  {
  1432. !         if  (type & N_EXT)  {
  1433.               (void) fprintf(stderr, "Duplicate symbol %s\n", sy->s_name);
  1434. ***************
  1435. *** 418,420
  1436.           
  1437. !     case  EXTERN|UNDEF:
  1438.           if  (val != 0)  {
  1439.  
  1440. --- 424,426 -----
  1441.           
  1442. !     case  N_EXT|N_UNDF:
  1443.           if  (val != 0)  {
  1444. ***************
  1445. *** 420,422
  1446.           if  (val != 0)  {
  1447. !             sy->s_type = COMM;
  1448.               addit(&comtab, sy);
  1449.  
  1450. --- 426,428 -----
  1451.           if  (val != 0)  {
  1452. !             sy->s_type = N_COMM;
  1453.               addit(&comtab, sy);
  1454. ***************
  1455. *** 428,430
  1456.           
  1457. !     case  EXTERN|ABS:
  1458.           sy->s_type = N_ABS;
  1459.  
  1460. --- 434,436 -----
  1461.           
  1462. !     case  N_EXT|N_ABS:
  1463.           sy->s_type = N_ABS;
  1464. ***************
  1465. *** 434,436
  1466.           
  1467. !     case  ABS:
  1468.           sy->s_type = N_ABS;
  1469.  
  1470. --- 440,442 -----
  1471.           
  1472. !     case  N_ABS:
  1473.           sy->s_type = N_ABS;
  1474. ***************
  1475. *** 439,442
  1476.           
  1477. !     case  EXTERN|TEXT:
  1478. !     case  TEXT:
  1479.           sy->s_type = N_TEXT;
  1480.  
  1481. --- 445,448 -----
  1482.           
  1483. !     case  N_EXT|N_TEXT:
  1484. !     case  N_TEXT:
  1485.           sy->s_type = N_TEXT;
  1486. ***************
  1487. *** 444,446
  1488.           tstr.t_bdest = 1;
  1489. !         if  (type & EXTERN)  {
  1490.               tstr.t_gbdest = 1;
  1491.  
  1492. --- 450,452 -----
  1493.           tstr.t_bdest = 1;
  1494. !         if  (type & N_EXT)  {
  1495.               tstr.t_gbdest = 1;
  1496. ***************
  1497. *** 453,456
  1498.           
  1499. !     case  BSS:
  1500. !     case  EXTERN|BSS:
  1501.           sy->s_type = N_BSS;
  1502.  
  1503. --- 459,462 -----
  1504.           
  1505. !     case  N_BSS:
  1506. !     case  N_EXT|N_BSS:
  1507.           sy->s_type = N_BSS;
  1508. ***************
  1509. *** 457,460
  1510.           goto    datrest;
  1511. !     case  DATA:
  1512. !     case  EXTERN|DATA:
  1513.           sy->s_type = N_DATA;
  1514.  
  1515. --- 463,466 -----
  1516.           goto    datrest;
  1517. !     case  N_DATA:
  1518. !     case  N_EXT|N_DATA:
  1519.           sy->s_type = N_DATA;
  1520. ***************
  1521. *** 462,464
  1522.           getde(fid, val, &dstr);
  1523. !         if  (type & EXTERN)
  1524.               sy->s_glob = 1;
  1525.  
  1526. --- 468,470 -----
  1527.           getde(fid, val, &dstr);
  1528. !         if  (type & N_EXT)
  1529.               sy->s_glob = 1;
  1530. ***************
  1531. *** 474,475
  1532.   
  1533.   /*
  1534.  
  1535. --- 480,482 -----
  1536.   
  1537.   /*
  1538. ***************
  1539. *** 487,490
  1540.   {
  1541. !     struct    bhdr    filhdr;
  1542. !     struct    reloc    crel;
  1543.       t_entry    tstr;
  1544.  
  1545. --- 494,497 -----
  1546.   {
  1547. !     struct    exec    filhdr;
  1548. !     struct    relocation_info    crel;
  1549.       t_entry    tstr;
  1550. ***************
  1551. *** 501,503
  1552.           return    -1;
  1553. !     if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  1554.           return    0;
  1555.  
  1556. --- 508,510 -----
  1557.           return    -1;
  1558. !     if  (filhdr.a_trsize <= 0  &&  filhdr.a_drsize <= 0)
  1559.           return    0;
  1560. ***************
  1561. *** 504,506
  1562.   
  1563. !     size  =  filhdr.rtsize;
  1564.   
  1565.  
  1566. --- 511,513 -----
  1567.   
  1568. !     size  =  filhdr.a_trsize;
  1569.   
  1570. ***************
  1571. *** 506,509
  1572.   
  1573. !     (void) lseek(inf, RTEXTPOS + offset, 0);
  1574. !     while  (size >= sizeof(struct reloc))  {
  1575.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1576.  
  1577. --- 513,516 -----
  1578.   
  1579. !     (void) lseek(inf, N_TXTOFF(filhdr) + filhdr.a_text + filhdr.a_data + offset, 0);
  1580. !     while  (size >= sizeof(struct relocation_info))  {
  1581.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1582. ***************
  1583. *** 511,513
  1584.   
  1585. !         pos = crel.rpos + outf->ef_tbase;
  1586.           gette(outf, pos, &tstr);
  1587.  
  1588. --- 518,520 -----
  1589.   
  1590. !         pos = crel.r_address + outf->ef_tbase;
  1591.           gette(outf, pos, &tstr);
  1592. ***************
  1593. *** 513,517
  1594.           gette(outf, pos, &tstr);
  1595. !         tstr.t_reloc = crel.rsize + 1;    /*  Fiddle!  YUK!!!  */
  1596. !         tstr.t_rdisp = crel.rdisp;
  1597. !         tstr.t_rptr = crel.rsegment;
  1598.           tstr.t_isrel = 1;
  1599.  
  1600. --- 520,522 -----
  1601.           gette(outf, pos, &tstr);
  1602. !         tstr.t_reloc = crel.r_length + 1;    /*  Fiddle!  YUK!!!  */
  1603.           tstr.t_isrel = 1;
  1604. ***************
  1605. *** 518,520
  1606.           putte(outf, pos, &tstr);
  1607. !         if  (crel.rsize == RLONG)  {
  1608.               gette(outf, pos+2, &tstr);
  1609.  
  1610. --- 523,525 -----
  1611.           putte(outf, pos, &tstr);
  1612. !         if  (crel.r_length == RLONG)  {
  1613.               gette(outf, pos+2, &tstr);
  1614. ***************
  1615. *** 553,555
  1616.           
  1617. !     case  EXTERN|UNDEF:
  1618.           if  (!sy->s_newsym)
  1619.  
  1620. --- 558,560 -----
  1621.           
  1622. !     case  N_EXT|N_UNDF:
  1623.           if  (!sy->s_newsym)
  1624. ***************
  1625. *** 558,560
  1626.           if  (val != 0)  {
  1627. !             sy->s_type = COMM;
  1628.               addit(&dreltab, sy);
  1629.  
  1630. --- 563,565 -----
  1631.           if  (val != 0)  {
  1632. !             sy->s_type = N_COMM;
  1633.               addit(&dreltab, sy);
  1634. ***************
  1635. *** 566,568
  1636.           
  1637. !     case  EXTERN|ABS:
  1638.           if  (!sy->s_newsym)  {
  1639.  
  1640. --- 571,573 -----
  1641.           
  1642. !     case  N_EXT|N_ABS:
  1643.           if  (!sy->s_newsym)  {
  1644. ***************
  1645. *** 577,579
  1646.           
  1647. !     case  EXTERN|TEXT:
  1648.           sy->s_type = N_TEXT;
  1649.  
  1650. --- 582,584 -----
  1651.           
  1652. !     case  N_EXT|N_TEXT:
  1653.           sy->s_type = N_TEXT;
  1654. ***************
  1655. *** 595,597
  1656.   
  1657. !     case  EXTERN|BSS:
  1658.           if  (!sy->s_newsym)
  1659.  
  1660. --- 600,602 -----
  1661.   
  1662. !     case  N_EXT|N_BSS:
  1663.           if  (!sy->s_newsym)
  1664. ***************
  1665. *** 602,604
  1666.   
  1667. !     case  EXTERN|DATA:
  1668.           if  (!sy->s_newsym)
  1669.  
  1670. --- 607,609 -----
  1671.   
  1672. !     case  N_EXT|N_DATA:
  1673.           if  (!sy->s_newsym)
  1674. ***************
  1675. *** 688,691
  1676.   {
  1677. !     struct    bhdr    filhdr;
  1678. !     struct    reloc    crel;
  1679.       t_entry    mtstr;
  1680.  
  1681. --- 693,696 -----
  1682.   {
  1683. !     struct    exec    filhdr;
  1684. !     struct    relocation_info    crel;
  1685.       t_entry    mtstr;
  1686. ***************
  1687. *** 705,707
  1688.           return;
  1689. !     if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  1690.           return;
  1691.  
  1692. --- 710,712 -----
  1693.           return;
  1694. !     if  (filhdr.a_trsize <= 0  &&  filhdr.a_drsize <= 0)
  1695.           return;
  1696. ***************
  1697. *** 708,710
  1698.   
  1699. !     size  =  filhdr.rtsize;
  1700.   
  1701.  
  1702. --- 713,715 -----
  1703.   
  1704. !     size  =  filhdr.a_trsize;
  1705.   
  1706. ***************
  1707. *** 710,713
  1708.   
  1709. !     (void) lseek(inf, RTEXTPOS + offset, 0);
  1710. !     for  (;  size >= sizeof(struct reloc);  size -= sizeof(crel))  {
  1711.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1712.  
  1713. --- 715,718 -----
  1714.   
  1715. !     (void) lseek(inf, N_TXTOFF(filhdr) + filhdr.a_text + filhdr.a_data + offset, 0);
  1716. !     for  (;  size >= sizeof(struct relocation_info);  size -= sizeof(crel))  {
  1717.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1718. ***************
  1719. *** 715,718
  1720.   
  1721. !         pos = crel.rpos + outf->ef_tbase;
  1722. !         mpos = crel.rpos + trelpos;
  1723.           gette(&mainfile, mpos, &mtstr);
  1724.  
  1725. --- 720,723 -----
  1726.   
  1727. !         pos = crel.r_address + outf->ef_tbase;
  1728. !         mpos = crel.r_address + trelpos;
  1729.           gette(&mainfile, mpos, &mtstr);
  1730. ***************
  1731. *** 718,721
  1732.           gette(&mainfile, mpos, &mtstr);
  1733. !         lval = gettw(outf, pos, (int)crel.rsize+1);
  1734. !         mval = gettw(&mainfile, mpos, (int)crel.rsize+1);
  1735.           
  1736.  
  1737. --- 723,726 -----
  1738.           gette(&mainfile, mpos, &mtstr);
  1739. !         lval = gettw(outf, pos, (int)crel.r_length+1);
  1740. !         mval = gettw(&mainfile, mpos, (int)crel.r_length+1);
  1741.           
  1742. ***************
  1743. *** 721,724
  1744.           
  1745. !         switch  (crel.rsegment)  {
  1746. !         case  RTEXT:
  1747.               if  (lval + trelpos - outf->ef_tbase != mval)
  1748.  
  1749. --- 726,730 -----
  1750.           
  1751. !         if ( !crel.r_extern ) {
  1752. !         switch  (crel.r_symbolnum)  {
  1753. !         case  N_TEXT:
  1754.               if  (lval + trelpos - outf->ef_tbase != mval)
  1755. ***************
  1756. *** 726,728
  1757.               continue;
  1758. !         case  RDATA:
  1759.               if  (donedrel)  {
  1760.  
  1761. --- 732,734 -----
  1762.               continue;
  1763. !         case  N_DATA:
  1764.               if  (donedrel)  {
  1765. ***************
  1766. *** 736,738
  1767.               continue;
  1768. !         case  RBSS:
  1769.               if  (donebrel)  {
  1770.  
  1771. --- 742,744 -----
  1772.               continue;
  1773. !         case  N_BSS:
  1774.               if  (donebrel)  {
  1775. ***************
  1776. *** 746,749
  1777.               continue;
  1778. !         case  REXT:
  1779. !             if  (crel.rsymbol >= outf->ef_stcnt)
  1780.                   lclash("Bad sy no");
  1781.  
  1782. --- 752,756 -----
  1783.               continue;
  1784. !               }
  1785. !           } else {
  1786. !             if  (crel.r_symbolnum >= outf->ef_stcnt)
  1787.                   lclash("Bad sy no");
  1788. ***************
  1789. *** 749,751
  1790.                   lclash("Bad sy no");
  1791. !             csymb = outf->ef_stvec[crel.rsymbol];
  1792.               if  (csymb == NULL)
  1793.  
  1794. --- 756,758 -----
  1795.                   lclash("Bad sy no");
  1796. !             csymb = outf->ef_stvec[crel.r_symbolnum];
  1797.               if  (csymb == NULL)
  1798. ***************
  1799. *** 772,774
  1800.                   break;
  1801. !             case  COMM:
  1802.                   reassign(csymb, mval - lval);
  1803.  
  1804. --- 779,781 -----
  1805.                   break;
  1806. !             case  N_COMM:
  1807.                   reassign(csymb, mval - lval);
  1808. ***************
  1809. *** 778,780
  1810.               mtstr.t_reldisp = lval;
  1811. -             break;
  1812.           }
  1813.  
  1814. --- 785,786 -----
  1815.               mtstr.t_reldisp = lval;
  1816.           }
  1817. ***************
  1818. *** 801,803
  1819.       
  1820. !     size  =  filhdr.rdsize;
  1821.       
  1822.  
  1823. --- 807,809 -----
  1824.       
  1825. !     size  =  filhdr.a_drsize;
  1826.       
  1827. ***************
  1828. *** 803,806
  1829.       
  1830. !     (void) lseek(inf, RDATAPOS + offset, 0);
  1831. !     for  (;  size >= sizeof(struct reloc); size -= sizeof(crel))  {
  1832.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1833.  
  1834. --- 809,813 -----
  1835.       
  1836. !     (void) lseek(inf, N_TXTOFF(filhdr) + filhdr.a_text + filhdr.a_data
  1837. !              + filhdr.a_trsize + offset, 0);
  1838. !     for  (;  size >= sizeof(struct relocation_info); size -= sizeof(crel))  {
  1839.           if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  1840. ***************
  1841. *** 808,810
  1842.   
  1843. !         if  (crel.rsize != RLONG)
  1844.               continue;
  1845.  
  1846. --- 815,817 -----
  1847.   
  1848. !         if  (crel.r_length != RLONG)
  1849.               continue;
  1850. ***************
  1851. *** 811,814
  1852.   
  1853. !         pos = crel.rpos + outf->ef_dbase;
  1854. !         mpos = crel.rpos + drelpos;
  1855.           getde(&mainfile, mpos, &mdstr);
  1856.  
  1857. --- 818,821 -----
  1858.   
  1859. !         pos = crel.r_address + outf->ef_dbase;
  1860. !         mpos = crel.r_address + drelpos;
  1861.           getde(&mainfile, mpos, &mdstr);
  1862. ***************
  1863. *** 814,819
  1864.           getde(&mainfile, mpos, &mdstr);
  1865. !         lval = getdw(outf, pos, (int)crel.rsize+1);
  1866. !         mval = getdw(&mainfile, mpos, (int)crel.rsize+1);
  1867. !         switch  (crel.rsegment)  {
  1868. !         case  RTEXT:
  1869.               if  (lval + trelpos - outf->ef_tbase != mval)
  1870.  
  1871. --- 821,827 -----
  1872.           getde(&mainfile, mpos, &mdstr);
  1873. !         lval = getdw(outf, pos, (int)crel.r_length+1);
  1874. !         mval = getdw(&mainfile, mpos, (int)crel.r_length+1);
  1875. !         if ( !crel.r_extern ) {
  1876. !         switch  (crel.r_symbolnum)  {
  1877. !         case  N_TEXT:
  1878.               if  (lval + trelpos - outf->ef_tbase != mval)
  1879. ***************
  1880. *** 821,823
  1881.               continue;
  1882. !         case  RDATA:
  1883.               if  (lval + drelpos - outf->ef_dbase != mval)
  1884.  
  1885. --- 829,831 -----
  1886.               continue;
  1887. !         case  N_DATA:
  1888.               if  (lval + drelpos - outf->ef_dbase != mval)
  1889. ***************
  1890. *** 825,827
  1891.               continue;
  1892. !         case  RBSS:
  1893.               if  (donebrel)  {
  1894.  
  1895. --- 833,835 -----
  1896.               continue;
  1897. !         case  N_BSS:
  1898.               if  (donebrel)  {
  1899. ***************
  1900. *** 835,838
  1901.               continue;
  1902. !         case  REXT:
  1903. !             if  (crel.rsymbol >= outf->ef_stcnt)
  1904.                   lclash("Bad sy no");
  1905.  
  1906. --- 843,847 -----
  1907.               continue;
  1908. !               }
  1909. !           } else { 
  1910. !             if  (crel.r_symbolnum >= outf->ef_stcnt)
  1911.                   lclash("Bad sy no");
  1912. ***************
  1913. *** 838,840
  1914.                   lclash("Bad sy no");
  1915. !             csymb = outf->ef_stvec[crel.rsymbol];
  1916.               if  (csymb == NULL)
  1917.  
  1918. --- 847,849 -----
  1919.                   lclash("Bad sy no");
  1920. !             csymb = outf->ef_stvec[crel.r_symbolnum];
  1921.               if  (csymb == NULL)
  1922. ***************
  1923. *** 861,863
  1924.                   break;
  1925. !             case  COMM:
  1926.                   reassign(csymb, mval - lval);
  1927.  
  1928. --- 870,872 -----
  1929.                   break;
  1930. !             case  N_COMM:
  1931.                   reassign(csymb, mval - lval);
  1932. ***************
  1933. *** 867,869
  1934.               mtstr.t_reldisp = lval;
  1935. -             break;
  1936.           }
  1937.  
  1938. --- 876,877 -----
  1939.               mtstr.t_reldisp = lval;
  1940.           }
  1941. diff -c1 ../temp2/unc.h ./unc.h
  1942. *** ../temp2/unc.h    Thu Mar 27 09:47:36 1986
  1943. --- ./unc.h    Thu Mar 27 09:49:19 1986
  1944. ***************
  1945. *** 35,37
  1946.       struct    symstr    *s_link;        /*  Next in duplicate labels */
  1947. !     unsigned    s_type    :  3;        /*  Symbol type  */
  1948.       unsigned    s_newsym:  1;        /*  A new symbol  */
  1949.  
  1950. --- 35,37 -----
  1951.       struct    symstr    *s_link;        /*  Next in duplicate labels */
  1952. !     unsigned    s_type    :  5;        /*  Symbol type  */
  1953.       unsigned    s_newsym:  1;        /*  A new symbol  */
  1954.