Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.36 KB | None | 0 0
  1. Index: Makefile
  2. ===================================================================
  3. RCS file: /cvsroot/pkgsrc/editors/mule/Makefile,v
  4. retrieving revision 1.51
  5. diff -u -p -d -r1.51 Makefile
  6. --- Makefile 4 Jul 2015 16:18:29 -0000 1.51
  7. +++ Makefile 27 Apr 2017 16:07:10 -0000
  8. @@ -25,7 +25,7 @@ GNU_CONFIGURE_MANDIR= ${PREFIX}/${PKGMAN
  9.  
  10. .include "../../mk/bsd.prefs.mk"
  11.  
  12. -CFLAGS+= -g
  13. +CFLAGS+= -g -fno-builtin-malloc -fno-strict-aliasing
  14.  
  15. CONFIGURE_ARGS+= ${MACHINE_ARCH}--${LOWER_OPSYS} --with-x --with-x-toolkit=lucid
  16. CONFIGURE_ARGS+= --terminal-face --mcpath --canna-libraries=${PREFIX}/lib
  17. Index: distinfo
  18. ===================================================================
  19. RCS file: /cvsroot/pkgsrc/editors/mule/distinfo,v
  20. retrieving revision 1.14
  21. diff -u -p -d -r1.14 distinfo
  22. --- distinfo 3 Nov 2015 03:32:18 -0000 1.14
  23. +++ distinfo 27 Apr 2017 16:07:10 -0000
  24. @@ -4,8 +4,8 @@ SHA1 (mule-2.3.tar.gz) = 52737767955caf2
  25. RMD160 (mule-2.3.tar.gz) = 52b93e746a7a796549a44104ab1898954df044bf
  26. SHA512 (mule-2.3.tar.gz) = 5f6a9047e6c9d752787d6cab3573516c6efd65cd901fbab74d314a5967e6c68b2dc7c2aa7454d8588d421553530c87dd3ee9692d523d818e01739580cb1201fd
  27. Size (mule-2.3.tar.gz) = 10240256 bytes
  28. -SHA1 (patch-aa) = 927ec514204ef97101fb3f4ab77eec1c71af23f1
  29. -SHA1 (patch-ab) = 7c2cf683e87320190af0306cf7d04b3638600944
  30. +SHA1 (patch-aa) = 4beddc75ea9d58423d62a9ff786a6c2b60caadca
  31. +SHA1 (patch-ab) = da4f43df6bddba83909989e60c1c0342f5d9d6ef
  32. SHA1 (patch-ac) = 170fa4f6c17c805dd32a90e8bfb3e38c48a9fc20
  33. SHA1 (patch-ad) = 7a52802cd614441320221f450cf97d4e30f40f2b
  34. SHA1 (patch-ae) = 1f020aaeb75cd7dd2b827ab34382e472add09719
  35. @@ -75,7 +75,7 @@ SHA1 (patch-lib-src_profile_c) = b4e74a5
  36. SHA1 (patch-lib-src_sorted-doc_c) = 9965f6a6722c2735dfc609a7a15c669f3df8fae4
  37. SHA1 (patch-lib-src_yow_c) = 38fb3e70395525ce8bb4816acd1b9e64c20f3735
  38. SHA1 (patch-src_abbrev_c) = c8dc21ca974625b8fe20e96bea37c61f709fbc1a
  39. -SHA1 (patch-src_alloc_c) = a5db486e10072ec3738df001aa555e35ae5a5a07
  40. +SHA1 (patch-src_alloc_c) = aaa4315c2487e3b32deb13940609fbcf4b895bce
  41. SHA1 (patch-src_buffer_h) = 3d2d0dba98a37265cc4df54bd14b6b51941d9c42
  42. SHA1 (patch-src_bytecode_c) = 93508ddb17e3ba2c7bb921caf85ce1e4e15791f3
  43. SHA1 (patch-src_callint_c) = 0b44807e049c12d2625c950efb14fd5409aba058
  44. Index: patches/patch-aa
  45. ===================================================================
  46. RCS file: /cvsroot/pkgsrc/editors/mule/patches/patch-aa,v
  47. retrieving revision 1.2
  48. diff -u -p -d -r1.2 patch-aa
  49. --- patches/patch-aa 1 Dec 2005 18:13:24 -0000 1.2
  50. +++ patches/patch-aa 27 Apr 2017 16:07:10 -0000
  51. @@ -1,6 +1,6 @@
  52. $NetBSD: patch-aa,v 1.2 2005/12/01 18:13:24 wiz Exp $
  53.  
  54. ---- src/s/netbsd.h.orig 1995-10-12 11:53:15.000000000 +0100
  55. +--- src/s/netbsd.h.orig 1995-10-12 10:53:15.000000000 +0000
  56. +++ src/s/netbsd.h
  57. @@ -3,6 +3,10 @@
  58. /* Get most of the stuff from bsd4.3 */
  59. @@ -13,18 +13,21 @@ $NetBSD: patch-aa,v 1.2 2005/12/01 18:13
  60. /* For mem-limits.h. */
  61. #define BSD4_2
  62.  
  63. -@@ -30,8 +34,8 @@
  64. +@@ -30,9 +34,10 @@
  65. #define NO_TERMIO
  66.  
  67. #define LIBS_DEBUG
  68. -/* -lutil is not needed for NetBSD >0.9. */
  69. -#define LIBS_SYSTEM -lutil -lcrypt
  70. +-#define LIBS_TERMCAP -ltermcap
  71. +#define LIBS_SYSTEM -lcrypt
  72. +
  73. - #define LIBS_TERMCAP -ltermcap
  74. ++#define TERMINFO
  75. ++#define LIBS_TERMCAP -lterminfo
  76.  
  77. #define NEED_ERRNO
  78. -@@ -40,7 +44,9 @@
  79. + #define SYSV_SYSTEM_DIR
  80. +@@ -40,7 +45,9 @@
  81. /* Netbsd has POSIX-style pgrp behavior. */
  82. #undef BSD_PGRPS
  83.  
  84. @@ -35,7 +38,7 @@ $NetBSD: patch-aa,v 1.2 2005/12/01 18:13
  85. /* These definitions should work for either dynamic or static linking,
  86. whichever is the default for `cc -nostdlib'. */
  87. #define HAVE_TEXT_START /* No need to define `start_of_text'. */
  88. -@@ -54,14 +60,34 @@
  89. +@@ -54,14 +61,34 @@
  90. #define N_BSSADDR(x) (N_ALIGN(x, N_DATADDR(x)+x.a_data))
  91. #define N_TRELOFF(x) N_RELOFF(x)
  92. #endif
  93. Index: patches/patch-ab
  94. ===================================================================
  95. RCS file: /cvsroot/pkgsrc/editors/mule/patches/patch-ab,v
  96. retrieving revision 1.3
  97. diff -u -p -d -r1.3 patch-ab
  98. --- patches/patch-ab 24 Dec 2011 17:07:07 -0000 1.3
  99. +++ patches/patch-ab 27 Apr 2017 16:07:10 -0000
  100. @@ -1,9 +1,10 @@
  101. $NetBSD: patch-ab,v 1.3 2011/12/24 17:07:07 dholland Exp $
  102.  
  103. ---- src/unexelf.c.orig 1994-10-21 05:21:00.000000000 +0100
  104. +--- src/unexelf.c.orig 1994-10-21 04:21:00.000000000 +0000
  105. +++ src/unexelf.c
  106. @@ -1,19 +1,22 @@
  107. - /* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992
  108. +-/* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992
  109. ++/* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992, 1999, 2000, 01, 02
  110. Free Software Foundation, Inc.
  111.  
  112. - This program is free software; you can redistribute it and/or modify
  113. @@ -57,245 +58,36 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  114. *
  115. * The boundaries within the a.out file may be adjusted with the data_start
  116. * and bss_start arguments. Either or both may be given as 0 for defaults.
  117. -@@ -98,64 +101,64 @@ temacs:
  118. - Link Info Adralgn Entsize
  119. -
  120. - [1] 1 2 0x80480d4 0xd4 0x13 .interp
  121. -- 0 0 0x1 0
  122. -+ 0 0 0x1 0
  123. -
  124. - [2] 5 2 0x80480e8 0xe8 0x388 .hash
  125. -- 3 0 0x4 0x4
  126. -+ 3 0 0x4 0x4
  127. -
  128. - [3] 11 2 0x8048470 0x470 0x7f0 .dynsym
  129. -- 4 1 0x4 0x10
  130. -+ 4 1 0x4 0x10
  131. -
  132. - [4] 3 2 0x8048c60 0xc60 0x3ad .dynstr
  133. -- 0 0 0x1 0
  134. -+ 0 0 0x1 0
  135. -
  136. - [5] 9 2 0x8049010 0x1010 0x338 .rel.plt
  137. -- 3 7 0x4 0x8
  138. -+ 3 7 0x4 0x8
  139. -
  140. - [6] 1 6 0x8049348 0x1348 0x3 .init
  141. -- 0 0 0x4 0
  142. -+ 0 0 0x4 0
  143. -
  144. - [7] 1 6 0x804934c 0x134c 0x680 .plt
  145. -- 0 0 0x4 0x4
  146. -+ 0 0 0x4 0x4
  147. -
  148. - [8] 1 6 0x80499cc 0x19cc 0x3c56f .text
  149. -- 0 0 0x4 0
  150. -+ 0 0 0x4 0
  151. -
  152. - [9] 1 6 0x8085f3c 0x3df3c 0x3 .fini
  153. -- 0 0 0x4 0
  154. -+ 0 0 0x4 0
  155. -
  156. - [10] 1 2 0x8085f40 0x3df40 0x69c .rodata
  157. -- 0 0 0x4 0
  158. -+ 0 0 0x4 0
  159. -
  160. - [11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1
  161. -- 0 0 0x4 0
  162. -+ 0 0 0x4 0
  163. -
  164. - [12] 1 3 0x8088330 0x3f330 0x20afc .data
  165. -- 0 0 0x4 0
  166. -+ 0 0 0x4 0
  167. -
  168. - [13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1
  169. -- 0 0 0x4 0
  170. -+ 0 0 0x4 0
  171. -
  172. - [14] 1 3 0x80a96cc 0x606cc 0x1a8 .got
  173. -- 0 0 0x4 0x4
  174. -+ 0 0 0x4 0x4
  175. -
  176. - [15] 6 3 0x80a9874 0x60874 0x80 .dynamic
  177. -- 4 0 0x4 0x8
  178. -+ 4 0 0x4 0x8
  179. -
  180. - [16] 8 3 0x80a98f4 0x608f4 0x449c .bss
  181. -- 0 0 0x4 0
  182. -+ 0 0 0x4 0
  183. -
  184. - [17] 2 0 0 0x608f4 0x9b90 .symtab
  185. -- 18 371 0x4 0x10
  186. -+ 18 371 0x4 0x10
  187. -
  188. - [18] 3 0 0 0x6a484 0x8526 .strtab
  189. -- 0 0 0x1 0
  190. -+ 0 0 0x1 0
  191. -
  192. - [19] 3 0 0 0x729aa 0x93 .shstrtab
  193. -- 0 0 0x1 0
  194. -+ 0 0 0x1 0
  195. -
  196. - [20] 1 0 0 0x72a3d 0x68b7 .comment
  197. -- 0 0 0x1 0
  198. -+ 0 0 0x1 0
  199. -
  200. - raid:/nfs/raid/src/dist-18.56/src> dump -h xemacs
  201. -
  202. -@@ -166,67 +169,67 @@ xemacs:
  203. - Link Info Adralgn Entsize
  204. -
  205. - [1] 1 2 0x80480d4 0xd4 0x13 .interp
  206. -- 0 0 0x1 0
  207. -+ 0 0 0x1 0
  208. -
  209. - [2] 5 2 0x80480e8 0xe8 0x388 .hash
  210. -- 3 0 0x4 0x4
  211. -+ 3 0 0x4 0x4
  212. -
  213. - [3] 11 2 0x8048470 0x470 0x7f0 .dynsym
  214. -- 4 1 0x4 0x10
  215. -+ 4 1 0x4 0x10
  216. -
  217. - [4] 3 2 0x8048c60 0xc60 0x3ad .dynstr
  218. -- 0 0 0x1 0
  219. -+ 0 0 0x1 0
  220. -
  221. - [5] 9 2 0x8049010 0x1010 0x338 .rel.plt
  222. -- 3 7 0x4 0x8
  223. -+ 3 7 0x4 0x8
  224. -
  225. - [6] 1 6 0x8049348 0x1348 0x3 .init
  226. -- 0 0 0x4 0
  227. -+ 0 0 0x4 0
  228. -
  229. - [7] 1 6 0x804934c 0x134c 0x680 .plt
  230. -- 0 0 0x4 0x4
  231. -+ 0 0 0x4 0x4
  232. -
  233. - [8] 1 6 0x80499cc 0x19cc 0x3c56f .text
  234. -- 0 0 0x4 0
  235. -+ 0 0 0x4 0
  236. -
  237. - [9] 1 6 0x8085f3c 0x3df3c 0x3 .fini
  238. -- 0 0 0x4 0
  239. -+ 0 0 0x4 0
  240. -
  241. - [10] 1 2 0x8085f40 0x3df40 0x69c .rodata
  242. -- 0 0 0x4 0
  243. -+ 0 0 0x4 0
  244. -
  245. - [11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1
  246. -- 0 0 0x4 0
  247. -+ 0 0 0x4 0
  248. -
  249. - [12] 1 3 0x8088330 0x3f330 0x20afc .data
  250. -- 0 0 0x4 0
  251. -+ 0 0 0x4 0
  252. -
  253. - [13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1
  254. -- 0 0 0x4 0
  255. -+ 0 0 0x4 0
  256. -
  257. - [14] 1 3 0x80a96cc 0x606cc 0x1a8 .got
  258. -- 0 0 0x4 0x4
  259. -+ 0 0 0x4 0x4
  260. -
  261. - [15] 6 3 0x80a9874 0x60874 0x80 .dynamic
  262. -- 4 0 0x4 0x8
  263. -+ 4 0 0x4 0x8
  264. -
  265. - [16] 8 3 0x80c6800 0x7d800 0 .bss
  266. -- 0 0 0x4 0
  267. -+ 0 0 0x4 0
  268. -
  269. - [17] 2 0 0 0x7d800 0x9b90 .symtab
  270. -- 18 371 0x4 0x10
  271. -+ 18 371 0x4 0x10
  272. -
  273. - [18] 3 0 0 0x87390 0x8526 .strtab
  274. -- 0 0 0x1 0
  275. -+ 0 0 0x1 0
  276. -
  277. - [19] 3 0 0 0x8f8b6 0x93 .shstrtab
  278. -- 0 0 0x1 0
  279. -+ 0 0 0x1 0
  280. -
  281. - [20] 1 0 0 0x8f949 0x68b7 .comment
  282. -- 0 0 0x1 0
  283. -+ 0 0 0x1 0
  284. -
  285. - [21] 1 3 0x80a98f4 0x608f4 0x1cf0c .data
  286. -- 0 0 0x4 0
  287. -+ 0 0 0x4 0
  288. -
  289. - * This is an example of how the file header is changed. "Shoff" is
  290. - * the section header offset within the file. Since that table is
  291. -@@ -276,20 +279,20 @@ temacs:
  292. - Type Offset Vaddr Paddr
  293. - Filesz Memsz Flags Align
  294. -
  295. --6 0x34 0x8048034 0
  296. --0xa0 0xa0 5 0
  297. -+6 0x34 0x8048034 0
  298. -+0xa0 0xa0 5 0
  299. -
  300. --3 0xd4 0 0
  301. --0x13 0 4 0
  302. -+3 0xd4 0 0
  303. -+0x13 0 4 0
  304. -
  305. --1 0x34 0x8048034 0
  306. --0x3f2f9 0x3f2f9 5 0x1000
  307. -+1 0x34 0x8048034 0
  308. -+0x3f2f9 0x3f2f9 5 0x1000
  309. -
  310. --1 0x3f330 0x8088330 0
  311. --0x215c4 0x25a60 7 0x1000
  312. -+1 0x3f330 0x8088330 0
  313. -+0x215c4 0x25a60 7 0x1000
  314. -
  315. --2 0x60874 0x80a9874 0
  316. --0x80 0 7 0
  317. -+2 0x60874 0x80a9874 0
  318. -+0x80 0 7 0
  319. -
  320. - raid:/nfs/raid/src/dist-18.56/src> dump -o xemacs
  321. -
  322. -@@ -298,42 +301,42 @@ xemacs:
  323. - Type Offset Vaddr Paddr
  324. - Filesz Memsz Flags Align
  325. -
  326. --6 0x34 0x8048034 0
  327. --0xa0 0xa0 5 0
  328. -+6 0x34 0x8048034 0
  329. -+0xa0 0xa0 5 0
  330. -
  331. --3 0xd4 0 0
  332. --0x13 0 4 0
  333. -+3 0xd4 0 0
  334. -+0x13 0 4 0
  335. -
  336. --1 0x34 0x8048034 0
  337. --0x3f2f9 0x3f2f9 5 0x1000
  338. -+1 0x34 0x8048034 0
  339. -+0x3f2f9 0x3f2f9 5 0x1000
  340. -
  341. --1 0x3f330 0x8088330 0
  342. --0x3e4d0 0x3e4d0 7 0x1000
  343. -+1 0x3f330 0x8088330 0
  344. -+0x3e4d0 0x3e4d0 7 0x1000
  345. +@@ -49,11 +52,6 @@ what you give them. Help stamp out sof
  346. + * The value you specify may be rounded down to a suitable boundary
  347. + * as required by the machine you are using.
  348. + *
  349. +- * Specifying zero for data_start means the boundary between text and data
  350. +- * should not be the same as when the program was loaded.
  351. +- * If NO_REMAP is defined, the argument data_start is ignored and the
  352. +- * segment boundaries are never changed.
  353. +- *
  354. + * Bss_start indicates how much of the data segment is to be saved in the
  355. + * a.out file and restored when the program is executed. It gives the lowest
  356. + * unsaved address, and is rounded up to a page boundary. The default when 0
  357. +@@ -63,9 +61,6 @@ what you give them. Help stamp out sof
  358. + *
  359. + * The new file is set up to start at entry_address.
  360. + *
  361. +- * If you make improvements I'd like to get them too.
  362. +- * harpo!utah-cs!thomas, thomas@Utah-20
  363. +- *
  364. + */
  365.  
  366. --2 0x60874 0x80a9874 0
  367. --0x80 0 7 0
  368. -+2 0x60874 0x80a9874 0
  369. -+0x80 0 7 0
  370. + /* Even more heavily modified by james@bigtex.cactus.org of Dell Computer Co.
  371. +@@ -315,25 +310,25 @@ Filesz Memsz Flags Alig
  372.  
  373.  
  374. */
  375. -
  376. +-
  377. -/* Modified by wtien@urbana.mcd.mot.com of Motorola Inc.
  378. - *
  379. ++
  380. +/* Modified by wtien@urbana.mcd.mot.com of Motorola Inc.
  381. + *
  382. * The above mechanism does not work if the unexeced ELF file is being
  383. @@ -325,7 +117,7 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  384. * 1. ELF header e_shstrndx field.
  385. * 2. section header sh_link and sh_info field.
  386. * 3. symbol table entry st_shndx field.
  387. -@@ -345,67 +348,67 @@ Filesz Memsz Flags Alig
  388. +@@ -345,85 +340,214 @@ Filesz Memsz Flags Alig
  389. Link Info Adralgn Entsize
  390.  
  391. [1] 1 2 0x80480d4 0xd4 0x13 .interp
  392. @@ -414,7 +206,35 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  393.  
  394. */
  395. -@@ -417,15 +420,130 @@ Filesz Memsz Flags Alig
  396. ++/*
  397. ++ * Modified by rdh@yottayotta.com of Yotta Yotta Incorporated.
  398. ++ *
  399. ++ * The code originally used mmap() to create a memory image of the new
  400. ++ * and old object files. This had a few handy features: (1) you get
  401. ++ * to use a cool system call like mmap, (2) no need to explicitly
  402. ++ * write out the new file before the close, and (3) no swap space
  403. ++ * requirements. Unfortunately, mmap() often fails to work with
  404. ++ * nfs-mounted file systems.
  405. ++ *
  406. ++ * So, instead of relying on the vm subsystem to do the file i/o for
  407. ++ * us, it's now done explicitly. A buffer of the right size for the
  408. ++ * file is dynamically allocated, and either the old_name is read into
  409. ++ * it, or it is initialized with the correct new executable contents,
  410. ++ * and then written to new_name.
  411. ++ */
  412. ++
  413. ++#ifndef emacs
  414. ++#define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1)
  415. ++#include <string.h>
  416. ++#else
  417. ++#include "config.h"
  418. ++#endif
  419. ++
  420. + #include <sys/types.h>
  421. + #include <stdio.h>
  422. + #include <sys/stat.h>
  423. + #include <memory.h>
  424. +-#include <string.h>
  425. #include <errno.h>
  426. #include <unistd.h>
  427. #include <fcntl.h>
  428. @@ -422,10 +242,34 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  429. #include <elf.h>
  430. +#endif
  431. #include <sys/mman.h>
  432. +-
  433. +-#ifndef emacs
  434. +-#define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1)
  435. +#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
  436. +#include <sys/elf_mips.h>
  437. +#include <sym.h>
  438. +#endif /* __sony_news && _SYSTYPE_SYSV */
  439. ++#if __sgi
  440. ++#include <syms.h> /* for HDRR declaration */
  441. ++#endif /* __sgi */
  442. ++
  443. ++#ifndef MAP_ANON
  444. ++#ifdef MAP_ANONYMOUS
  445. ++#define MAP_ANON MAP_ANONYMOUS
  446. + #else
  447. +-extern void fatal (char *, ...);
  448. ++#define MAP_ANON 0
  449. ++#endif
  450. ++#endif
  451. ++
  452. ++#ifdef MCPATH /* hir, 1993.8.4 */
  453. ++#undef open
  454. ++#undef chmod
  455. ++#endif
  456. ++
  457. ++#ifndef MAP_FAILED
  458. ++#define MAP_FAILED ((void *) -1)
  459. ++#endif
  460. +
  461. +#if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__)
  462. +/* Declare COFF debugging symbol table. This used to be in
  463. @@ -466,51 +310,27 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  464. +/*
  465. + * NetBSD does not have normal-looking user-land ELF support.
  466. + */
  467. -+# if defined(__alpha__) || defined(__x86_64__) || defined(__sparc64__) || defined(_LP64)
  468. -+# define ELFSIZE 64
  469. -+# else
  470. -+# define ELFSIZE 32
  471. -+# endif
  472. +# include <sys/exec_elf.h>
  473. +
  474. -+#ifndef PT_LOAD
  475. -+# define PT_LOAD Elf_pt_load
  476. -+# define SHT_SYMTAB Elf_sht_symtab
  477. -+# define SHT_DYNSYM Elf_sht_dynsym
  478. -+# define SHT_NULL Elf_sht_null
  479. -+# define SHT_NOBITS Elf_sht_nobits
  480. -+# define SHT_REL Elf_sht_rel
  481. -+# define SHT_RELA Elf_sht_rela
  482. -+
  483. -+# define SHN_UNDEF Elf_eshn_undefined
  484. -+# define SHN_ABS Elf_eshn_absolute
  485. -+# define SHN_COMMON Elf_eshn_common
  486. -+#endif
  487. -+
  488. -+/*
  489. -+ * The magic of picking the right size types is handled by the ELFSIZE
  490. -+ * definition above.
  491. -+ */
  492. -+# ifdef __STDC__
  493. -+# define ElfW(type) Elf_##type
  494. -+# else
  495. -+# define ElfW(type) Elf_/**/type
  496. -+# endif
  497. -+
  498. -+# ifdef __alpha__
  499. -+# include <sys/exec_ecoff.h>
  500. -+# define HDRR struct ecoff_symhdr
  501. -+# define pHDRR HDRR *
  502. -+# endif /* __alpha__*/
  503. ++# ifndef PT_LOAD
  504. ++# define PT_LOAD Elf_pt_load
  505. ++# if 0 /* was in pkgsrc patches for 20.7 */
  506. ++# define SHT_PROGBITS Elf_sht_progbits
  507. ++# endif
  508. ++# define SHT_SYMTAB Elf_sht_symtab
  509. ++# define SHT_DYNSYM Elf_sht_dynsym
  510. ++# define SHT_NULL Elf_sht_null
  511. ++# define SHT_NOBITS Elf_sht_nobits
  512. ++# define SHT_REL Elf_sht_rel
  513. ++# define SHT_RELA Elf_sht_rela
  514. +
  515. -+# ifdef __mips__
  516. -+# define SHT_MIPS_DEBUG DT_MIPS_FLAGS
  517. -+# define HDRR struct Elf_Shdr
  518. -+# endif /* __mips__ */
  519. ++# define SHN_UNDEF Elf_eshn_undefined
  520. ++# define SHN_ABS Elf_eshn_absolute
  521. ++# define SHN_COMMON Elf_eshn_common
  522. ++# endif /* !PT_LOAD */
  523. +
  524. +#endif /* __NetBSD__ */
  525. +
  526. -+
  527. +#ifdef __OpenBSD__
  528. +# include <sys/exec_elf.h>
  529. +#endif
  530. @@ -521,35 +341,28 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  531. +
  532. +#ifndef ElfW
  533. +# ifdef __STDC__
  534. -+# define ElfW(type) Elf32_##type
  535. ++# define ElfBitsW(bits, type) Elf##bits##_##type
  536. +# else
  537. -+# define ElfW(type) Elf32_/**/type
  538. ++# define ElfBitsW(bits, type) Elf/**/bits/**/_/**/type
  539. +# endif
  540. -+#endif
  541. -
  542. - #ifndef emacs
  543. - #define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1)
  544. - #else
  545. -+#include <config.h>
  546. - extern void fatal (char *, ...);
  547. ++# ifndef ELFSIZE
  548. ++# ifdef _LP64
  549. ++# define ELFSIZE 64
  550. ++# else
  551. ++# define ELFSIZE 32
  552. ++# endif
  553. ++# endif
  554. ++ /* This macro expands `bits' before invoking ElfBitsW. */
  555. ++# define ElfExpandBitsW(bits, type) ElfBitsW (bits, type)
  556. ++# define ElfW(type) ElfExpandBitsW (ELFSIZE, type)
  557. #endif
  558.  
  559. -+#if defined ( __sony_news) && defined (_SYSTYPE_SYSV)
  560. -+# define HAVE_MIPS_SBSS
  561. -+#endif
  562. -+
  563. -+#if (defined (__mips__) || defined (__powerpc__)) && (defined(__NetBSD__) || defined(__OpenBSD__))
  564. -+# define HAVE_MIPS_SBSS
  565. -+#endif
  566. -+
  567. #ifndef ELF_BSS_SECTION_NAME
  568. - #define ELF_BSS_SECTION_NAME ".bss"
  569. - #endif
  570. -@@ -433,15 +551,38 @@ extern void fatal (char *, ...);
  571. +@@ -433,15 +557,38 @@ extern void fatal (char *, ...);
  572. /* Get the address of a particular section or program header entry,
  573. * accounting for the size of the entries.
  574. */
  575. -+/*
  576. ++/*
  577. + On PPC Reference Platform running Solaris 2.5.1
  578. + the plt section is also of type NOBI like the bss section.
  579. + (not really stored) and therefore sections after the bss
  580. @@ -558,7 +371,7 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  581. + Thus, we modify the test from
  582. + if (NEW_SECTION_H (nn).sh_offset >= new_data2_offset)
  583. + to
  584. -+ if (NEW_SECTION_H (nn).sh_offset >=
  585. ++ if (NEW_SECTION_H (nn).sh_offset >=
  586. + OLD_SECTION_H (old_bss_index-1).sh_offset)
  587. + This is just a hack. We should put the new data section
  588. + before the .plt section.
  589. @@ -588,67 +401,78 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  590.  
  591. #define PATCH_INDEX(n) \
  592. do { \
  593. -@@ -451,9 +592,9 @@ typedef unsigned char byte;
  594. +@@ -451,9 +598,8 @@ typedef unsigned char byte;
  595.  
  596. /* Round X up to a multiple of Y. */
  597.  
  598. -int
  599. -+ElfW(Addr)
  600. - round_up (x, y)
  601. +-round_up (x, y)
  602. - int x, y;
  603. -+ ElfW(Addr) x, y;
  604. ++static ElfW(Addr)
  605. ++round_up (ElfW(Addr) x, ElfW(Addr) y)
  606. {
  607. int rem = x % y;
  608. if (rem == 0)
  609. -@@ -461,6 +602,47 @@ round_up (x, y)
  610. +@@ -461,6 +607,39 @@ round_up (x, y)
  611. return x - rem + y;
  612. }
  613.  
  614. -+#if defined(__alpha__) || (defined ( __sony_news) && defined (_SYSTYPE_SYSV))
  615. -+/* We are using ECOFF symbols embedded in ELF. */
  616. ++/* Return the index of the section named NAME.
  617. ++ SECTION_NAMES, FILE_NAME and FILE_H give information
  618. ++ about the file we are looking in.
  619. +
  620. -+void
  621. -+relocate_ecoff_symhdr(symhdr, diff)
  622. -+ HDRR *symhdr;
  623. -+ ElfW(Word) diff;
  624. -+{
  625. -+ symhdr->cbLineOffset += diff;
  626. -+ symhdr->cbDnOffset += diff;
  627. -+ symhdr->cbPdOffset += diff;
  628. -+ symhdr->cbSymOffset += diff;
  629. -+ symhdr->cbOptOffset += diff;
  630. -+ symhdr->cbAuxOffset += diff;
  631. -+ symhdr->cbSsOffset += diff;
  632. -+ symhdr->cbSsExtOffset += diff;
  633. -+ symhdr->cbFdOffset += diff;
  634. -+ symhdr->cbRfdOffset += diff;
  635. -+ symhdr->cbExtOffset += diff;
  636. -+}
  637. -+#endif /* __alpha__ or __sony_news and systype_sysv */
  638. ++ If we don't find the section NAME, that is a fatal error
  639. ++ if NOERROR is 0; we return -1 if NOERROR is nonzero. */
  640. +
  641. -+#ifdef notyet
  642. -+void
  643. -+relocate_elf_proghdr(p, diff)
  644. -+ HDRR *symhdr;
  645. -+ ElfW(Word) diff;
  646. ++static int
  647. ++find_section (char *name, char *section_names, char *file_name, ElfW(Ehdr) *old_file_h, ElfW(Shdr) *old_section_h, int noerror)
  648. +{
  649. -+ phdr->sh_name += diff;
  650. -+ phdr->sh_type += diff;
  651. -+ phdr->sh_flags += diff;
  652. -+ phdr->sh_addr += diff;
  653. -+ phdr->sh_offset += diff;
  654. -+ phdr->sh_size += diff;
  655. -+ phdr->sh_link += diff;
  656. -+ phdr->sh_info += diff;
  657. -+ phdr->sh_addralign += diff;
  658. -+ phdr->sh_entsize += diff;
  659. -+};
  660. -+#endif /* notyet */
  661. ++ int idx;
  662. ++
  663. ++ for (idx = 1; idx < old_file_h->e_shnum; idx++)
  664. ++ {
  665. ++#ifdef DEBUG
  666. ++ fprintf (stderr, "Looking for %s - found %s\n", name,
  667. ++ section_names + OLD_SECTION_H (idx).sh_name);
  668. ++#endif
  669. ++ if (!strcmp (section_names + OLD_SECTION_H (idx).sh_name,
  670. ++ name))
  671. ++ break;
  672. ++ }
  673. ++ if (idx == old_file_h->e_shnum)
  674. ++ {
  675. ++ if (noerror)
  676. ++ return -1;
  677. ++ else
  678. ++ fatal ("Can't find %s in %s.\n", name, file_name);
  679. ++ }
  680. ++
  681. ++ return idx;
  682. ++}
  683. +
  684. /* ****************************************************************
  685. * unexec
  686. *
  687. -@@ -483,19 +665,23 @@ unexec (new_name, old_name, data_start,
  688. +@@ -471,34 +650,45 @@ round_up (x, y)
  689. + *
  690. + */
  691. + void
  692. +-unexec (new_name, old_name, data_start, bss_start, entry_address)
  693. +- char *new_name, *old_name;
  694. +- unsigned data_start, bss_start, entry_address;
  695. ++unexec (char *new_name, char *old_name, unsigned data_start, unsigned bss_start, unsigned entry_address)
  696. + {
  697. + int new_file, old_file, new_file_size;
  698. +
  699. + /* Pointers to the base of the image of the two files. */
  700. + caddr_t old_base, new_base;
  701. +
  702. ++#if MAP_ANON == 0
  703. ++ int mmap_fd;
  704. ++#else
  705. ++# define mmap_fd -1
  706. ++#endif
  707. ++
  708. /* Pointers to the file, program and section headers for the old and new
  709. * files.
  710. */
  711. @@ -666,30 +490,57 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  712. - Elf32_Word old_bss_size, new_data2_size;
  713. - Elf32_Off new_data2_offset;
  714. - Elf32_Addr new_data2_addr;
  715. +-
  716. +- int n, nn, old_bss_index, old_data_index, new_data2_index;
  717. + ElfW(Addr) old_bss_addr, new_bss_addr;
  718. + ElfW(Word) old_bss_size, new_data2_size;
  719. + ElfW(Off) new_data2_offset;
  720. + ElfW(Addr) new_data2_addr;
  721. -
  722. - int n, nn, old_bss_index, old_data_index, new_data2_index;
  723. -+#ifdef HAVE_MIPS_SBSS
  724. -+ int old_sbss_index, old_mdebug_index;
  725. -+ int bss_phdr_index;
  726. -+#endif /* HAVE_MIPS_SBSS */
  727. ++ ElfW(Off) old_bss_offset;
  728. ++ ElfW(Word) new_data2_incr, new_data2_shincr;
  729. ++
  730. ++ int n, nn;
  731. ++ int old_bss_index, old_sbss_index;
  732. ++ int old_data_index, new_data2_index;
  733. ++ int old_mdebug_index;
  734. struct stat stat_buf;
  735. ++ int old_file_size;
  736.  
  737. - /* Open the old file & map it into the address space. */
  738. -@@ -508,7 +694,8 @@ unexec (new_name, old_name, data_start,
  739. +- /* Open the old file & map it into the address space. */
  740. ++ /* Open the old file, allocate a buffer of the right size, and read
  741. ++ * in the file contents. */
  742. +
  743. + old_file = open (old_name, O_RDONLY);
  744. +
  745. +@@ -508,90 +698,127 @@ unexec (new_name, old_name, data_start,
  746. if (fstat (old_file, &stat_buf) == -1)
  747. fatal ("Can't fstat (%s): errno %d\n", old_name, errno);
  748.  
  749. - old_base = mmap (0, stat_buf.st_size, PROT_READ, MAP_SHARED, old_file, 0);
  750. -+ old_base = mmap ((caddr_t) 0, stat_buf.st_size, PROT_READ, MAP_SHARED,
  751. -+ old_file, 0);
  752. ++#if MAP_ANON == 0
  753. ++ mmap_fd = open ("/dev/zero", O_RDONLY);
  754. ++ if (mmap_fd < 0)
  755. ++ fatal ("Can't open /dev/zero for reading: errno %d\n", errno);
  756. ++#endif
  757.  
  758. - if (old_base == (caddr_t) -1)
  759. - fatal ("Can't mmap (%s): errno %d\n", old_name, errno);
  760. -@@ -520,9 +707,9 @@ unexec (new_name, old_name, data_start,
  761. +- if (old_base == (caddr_t) -1)
  762. +- fatal ("Can't mmap (%s): errno %d\n", old_name, errno);
  763. ++ /* We cannot use malloc here because that may use sbrk. If it does,
  764. ++ we'd dump our temporary buffers with Emacs, and we'd have to be
  765. ++ extra careful to use the correct value of sbrk(0) after
  766. ++ allocating all buffers in the code below, which we aren't. */
  767. ++ old_file_size = stat_buf.st_size;
  768. ++ old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE,
  769. ++ MAP_ANON | MAP_PRIVATE, mmap_fd, 0);
  770. ++ if (old_base == MAP_FAILED)
  771. ++ fatal ("Can't allocate buffer for %s\n", old_name);
  772. +
  773. +-#ifdef DEBUG
  774. +- fprintf (stderr, "mmap (%s, %x) -> %x\n", old_name, stat_buf.st_size,
  775. +- old_base);
  776. +-#endif
  777. ++ if (read (old_file, old_base, stat_buf.st_size) != stat_buf.st_size)
  778. ++ fatal ("Didn't read all of %s: errno %d\n", old_name, errno);
  779.  
  780. /* Get pointers to headers & section names */
  781.  
  782. @@ -702,57 +553,61 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  783. old_section_names = (char *) old_base
  784. + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset;
  785.  
  786. -@@ -544,16 +731,61 @@ unexec (new_name, old_name, data_start,
  787. - if (old_bss_index == old_file_h->e_shnum)
  788. - fatal ("Can't find .bss in %s.\n", old_name, 0);
  789. ++ /* Find the mdebug section, if any. */
  790. ++
  791. ++ old_mdebug_index = find_section (".mdebug", old_section_names,
  792. ++ old_name, old_file_h, old_section_h, 1);
  793. ++
  794. + /* Find the old .bss section. Figure out parameters of the new
  795. + * data2 and bss sections.
  796. + */
  797.  
  798. -+#ifdef HAVE_MIPS_SBSS
  799. -+ for (old_sbss_index = 1; old_sbss_index < (int) old_file_h->e_shnum;
  800. -+ old_sbss_index++)
  801. -+ {
  802. -+#ifdef DEBUG
  803. -+ fprintf (stderr, "Looking for .sbss - found %s\n",
  804. -+ old_section_names + OLD_SECTION_H (old_sbss_index).sh_name);
  805. -+#endif
  806. -+ if (!strcmp (old_section_names + OLD_SECTION_H (old_sbss_index).sh_name,
  807. -+ ".sbss"))
  808. -+ break;
  809. -+ }
  810. -+ if (old_sbss_index == old_file_h->e_shnum)
  811. -+ {
  812. -+ old_bss_addr = OLD_SECTION_H(old_bss_index).sh_addr;
  813. -+ old_bss_size = OLD_SECTION_H(old_bss_index).sh_size;
  814. -+ new_data2_offset = OLD_SECTION_H(old_bss_index).sh_offset;
  815. +- for (old_bss_index = 1; old_bss_index < (int) old_file_h->e_shnum;
  816. +- old_bss_index++)
  817. ++ old_bss_index = find_section (".bss", old_section_names,
  818. ++ old_name, old_file_h, old_section_h, 0);
  819. ++
  820. ++ old_sbss_index = find_section (".sbss", old_section_names,
  821. ++ old_name, old_file_h, old_section_h, 1);
  822. ++ if (old_sbss_index != -1)
  823. ++ if (OLD_SECTION_H (old_sbss_index).sh_type == SHT_PROGBITS)
  824. ++ old_sbss_index = -1;
  825. ++
  826. ++ if (old_sbss_index == -1)
  827. + {
  828. +-#ifdef DEBUG
  829. +- fprintf (stderr, "Looking for .bss - found %s\n",
  830. +- old_section_names + OLD_SECTION_H (old_bss_index).sh_name);
  831. +-#endif
  832. +- if (!strcmp (old_section_names + OLD_SECTION_H (old_bss_index).sh_name,
  833. +- ELF_BSS_SECTION_NAME))
  834. +- break;
  835. ++ old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr;
  836. ++ old_bss_size = OLD_SECTION_H (old_bss_index).sh_size;
  837. ++ old_bss_offset = OLD_SECTION_H (old_bss_index).sh_offset;
  838. + new_data2_index = old_bss_index;
  839. + }
  840. + else
  841. + {
  842. -+ old_bss_addr = OLD_SECTION_H(old_sbss_index).sh_addr;
  843. -+ old_bss_size = OLD_SECTION_H(old_bss_index).sh_size
  844. -+ + OLD_SECTION_H(old_sbss_index).sh_size;
  845. -+ new_data2_offset = OLD_SECTION_H(old_sbss_index).sh_offset;
  846. ++ old_bss_addr = OLD_SECTION_H (old_sbss_index).sh_addr;
  847. ++ old_bss_size = OLD_SECTION_H (old_bss_index).sh_size
  848. ++ + OLD_SECTION_H (old_sbss_index).sh_size;
  849. ++ old_bss_offset = OLD_SECTION_H (old_sbss_index).sh_offset;
  850. + new_data2_index = old_sbss_index;
  851. -+ }
  852. -+
  853. -+ for (old_mdebug_index = 1; old_mdebug_index < (int) old_file_h->e_shnum;
  854. -+ old_mdebug_index++)
  855. -+ {
  856. -+#ifdef DEBUG
  857. -+ fprintf (stderr, "Looking for .mdebug - found %s\n",
  858. -+ old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name);
  859. -+#endif
  860. -+ if (!strcmp (old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name,
  861. -+ ".mdebug"))
  862. -+ break;
  863. -+ }
  864. -+ if (old_mdebug_index == old_file_h->e_shnum)
  865. -+ old_mdebug_index = 0;
  866. -+#else /* not HAVE_MIPS_SBSS */
  867. - old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr;
  868. - old_bss_size = OLD_SECTION_H (old_bss_index).sh_size;
  869. + }
  870. +- if (old_bss_index == old_file_h->e_shnum)
  871. +- fatal ("Can't find .bss in %s.\n", old_name, 0);
  872. +
  873. +- old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr;
  874. +- old_bss_size = OLD_SECTION_H (old_bss_index).sh_size;
  875. -#if defined(emacs) || !defined(DEBUG)
  876. - new_bss_addr = (Elf32_Addr) sbrk (0);
  877. -+#endif /* not HAVE_MIPS_SBSS */
  878. ++ /* Find the old .data section. Figure out parameters of
  879. ++ the new data2 and bss sections. */
  880. ++
  881. ++ old_data_index = find_section (".data", old_section_names,
  882. ++ old_name, old_file_h, old_section_h, 0);
  883. ++
  884. +#if defined (emacs) || !defined (DEBUG)
  885. + new_bss_addr = (ElfW(Addr)) sbrk (0);
  886. #else
  887. @@ -760,72 +615,131 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  888. #endif
  889. new_data2_addr = old_bss_addr;
  890. new_data2_size = new_bss_addr - old_bss_addr;
  891. -+#ifndef HAVE_MIPS_SBSS
  892. - new_data2_offset = OLD_SECTION_H (old_bss_index).sh_offset;
  893. -+#endif /* not HAVE_MIPS_SBSS */
  894. +- new_data2_offset = OLD_SECTION_H (old_bss_index).sh_offset;
  895. ++ new_data2_offset = OLD_SECTION_H (old_data_index).sh_offset
  896. ++ + (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr);
  897. ++ /* This is the amount by which the sections following the bss sections
  898. ++ must be shifted in the image. It can differ from new_data2_size if
  899. ++ the end of the old .data section (and thus the offset of the .bss
  900. ++ section) was unaligned. */
  901. ++ new_data2_incr = new_data2_size + (new_data2_offset - old_bss_offset);
  902. ++ new_data2_shincr = round_up(new_data2_incr, old_program_h->p_align);
  903.  
  904. #ifdef DEBUG
  905. fprintf (stderr, "old_bss_index %d\n", old_bss_index);
  906. -@@ -582,15 +814,20 @@ unexec (new_name, old_name, data_start,
  907. + fprintf (stderr, "old_bss_addr %x\n", old_bss_addr);
  908. + fprintf (stderr, "old_bss_size %x\n", old_bss_size);
  909. ++ fprintf (stderr, "old_bss_offset %x\n", old_bss_offset);
  910. + fprintf (stderr, "new_bss_addr %x\n", new_bss_addr);
  911. + fprintf (stderr, "new_data2_addr %x\n", new_data2_addr);
  912. + fprintf (stderr, "new_data2_size %x\n", new_data2_size);
  913. + fprintf (stderr, "new_data2_offset %x\n", new_data2_offset);
  914. ++ fprintf (stderr, "new_data2_incr %x\n", new_data2_incr);
  915. + #endif
  916. +
  917. + if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size)
  918. + fatal (".bss shrank when undumping???\n", 0, 0);
  919. +
  920. +- /* Set the output file to the right size and mmap it. Set
  921. +- * pointers to various interesting objects. stat_buf still has
  922. +- * old_file data.
  923. ++ /* Set the output file to the right size. Allocate a buffer to hold
  924. ++ * the image of the new file. Set pointers to various interesting
  925. ++ * objects. stat_buf still has old_file data.
  926. + */
  927. +
  928. + new_file = open (new_name, O_RDWR | O_CREAT, 0666);
  929. + if (new_file < 0)
  930. + fatal ("Can't creat (%s): errno %d\n", new_name, errno);
  931. +
  932. +- new_file_size = stat_buf.st_size + old_file_h->e_shentsize + new_data2_size;
  933. ++ new_file_size = stat_buf.st_size + old_file_h->e_shentsize + new_data2_shincr;
  934. +
  935. if (ftruncate (new_file, new_file_size))
  936. fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);
  937.  
  938. - new_base = mmap (0, new_file_size, PROT_READ | PROT_WRITE, MAP_SHARED,
  939. - new_file, 0);
  940. -+#ifdef UNEXEC_USE_MAP_PRIVATE
  941. -+ new_base = mmap ((caddr_t) 0, new_file_size, PROT_READ | PROT_WRITE,
  942. -+ MAP_PRIVATE, new_file, 0);
  943. -+#else
  944. -+ new_base = mmap ((caddr_t) 0, new_file_size, PROT_READ | PROT_WRITE,
  945. -+ MAP_SHARED, new_file, 0);
  946. -+#endif
  947. -
  948. - if (new_base == (caddr_t) -1)
  949. - fatal ("Can't mmap (%s): errno %d\n", new_name, errno);
  950. -
  951. +-
  952. +- if (new_base == (caddr_t) -1)
  953. +- fatal ("Can't mmap (%s): errno %d\n", new_name, errno);
  954. +-
  955. - new_file_h = (Elf32_Ehdr *) new_base;
  956. - new_program_h = (Elf32_Phdr *) ((byte *) new_base + old_file_h->e_phoff);
  957. - new_section_h = (Elf32_Shdr *)
  958. +- ((byte *) new_base + old_file_h->e_shoff + new_data2_size);
  959. ++ new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE,
  960. ++ MAP_ANON | MAP_PRIVATE, mmap_fd, 0);
  961. ++ if (new_base == MAP_FAILED)
  962. ++ fatal ("Can't allocate buffer for %s\n", old_name);
  963. ++
  964. + new_file_h = (ElfW(Ehdr) *) new_base;
  965. + new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff);
  966. + new_section_h = (ElfW(Shdr) *)
  967. - ((byte *) new_base + old_file_h->e_shoff + new_data2_size);
  968. ++ ((byte *) new_base + old_file_h->e_shoff + new_data2_shincr);
  969.  
  970. /* Make our new file, program and section headers as copies of the
  971. -@@ -633,8 +870,14 @@ unexec (new_name, old_name, data_start,
  972. + * originals.
  973. +@@ -608,7 +835,7 @@ unexec (new_name, old_name, data_start,
  974. + * further away now.
  975. + */
  976. +
  977. +- new_file_h->e_shoff += new_data2_size;
  978. ++ new_file_h->e_shoff += new_data2_shincr;
  979. + new_file_h->e_shnum += 1;
  980. +
  981. + #ifdef DEBUG
  982. +@@ -629,12 +856,22 @@ unexec (new_name, old_name, data_start,
  983. + for (n = new_file_h->e_phnum - 1; n >= 0; n--)
  984. + {
  985. + /* Compute maximum of all requirements for alignment of section. */
  986. +- int alignment = (NEW_PROGRAM_H (n)).p_align;
  987. ++ ElfW(Word) alignment = (NEW_PROGRAM_H (n)).p_align;
  988. if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment)
  989. alignment = OLD_SECTION_H (old_bss_index).sh_addralign;
  990.  
  991. -+#ifdef HAVE_MIPS_SBSS
  992. +- if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_bss_addr)
  993. +- fatal ("Program segment above .bss in %s\n", old_name, 0);
  994. ++#ifdef __sgi
  995. ++ /* According to r02kar@x4u2.desy.de (Karsten Kuenne)
  996. ++ and oliva@gnu.org (Alexandre Oliva), on IRIX 5.2, we
  997. ++ always get "Program segment above .bss" when dumping
  998. ++ when the executable doesn't have an sbss section. */
  999. ++ if (old_sbss_index != -1)
  1000. ++#endif /* __sgi */
  1001. + if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz
  1002. -+ > round_up (old_bss_addr, alignment))
  1003. -+ fatal ("Program segment above .bss in %s\n", old_name, 0);
  1004. -+#else /* not HAVE_MIPS_SBSS */
  1005. - if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_bss_addr)
  1006. - fatal ("Program segment above .bss in %s\n", old_name, 0);
  1007. -+#endif /* not HAVE_MIPS_SBSS */
  1008. ++ > (old_sbss_index == -1
  1009. ++ ? old_bss_addr
  1010. ++ : round_up (old_bss_addr, alignment)))
  1011. ++ fatal ("Program segment above .bss in %s\n", old_name, 0);
  1012.  
  1013. if (NEW_PROGRAM_H (n).p_type == PT_LOAD
  1014. && (round_up ((NEW_PROGRAM_H (n)).p_vaddr
  1015. -@@ -646,9 +889,16 @@ unexec (new_name, old_name, data_start,
  1016. +@@ -646,10 +883,12 @@ unexec (new_name, old_name, data_start,
  1017. if (n < 0)
  1018. fatal ("Couldn't find segment next to .bss in %s\n", old_name, 0);
  1019.  
  1020. - NEW_PROGRAM_H (n).p_filesz += new_data2_size;
  1021. -+#ifdef HAVE_MIPS_SBSS
  1022. -+ bss_phdr_index = n;
  1023. -+#endif
  1024. -+
  1025. + /* Make sure that the size includes any padding before the old .bss
  1026. + section. */
  1027. + NEW_PROGRAM_H (n).p_filesz = new_bss_addr - NEW_PROGRAM_H (n).p_vaddr;
  1028. NEW_PROGRAM_H (n).p_memsz = NEW_PROGRAM_H (n).p_filesz;
  1029.  
  1030. -+
  1031. - #if 0 /* Maybe allow section after data2 - does this ever happen? */
  1032. +-#if 0 /* Maybe allow section after data2 - does this ever happen? */
  1033. ++#ifdef IRIX5 /* allow section after data2 */
  1034. for (n = new_file_h->e_phnum - 1; n >= 0; n--)
  1035. {
  1036. -@@ -675,18 +925,27 @@ unexec (new_name, old_name, data_start,
  1037. + if (NEW_PROGRAM_H (n).p_vaddr
  1038. +@@ -657,7 +896,7 @@ unexec (new_name, old_name, data_start,
  1039. + NEW_PROGRAM_H (n).p_vaddr += new_data2_size - old_bss_size;
  1040. +
  1041. + if (NEW_PROGRAM_H (n).p_offset >= new_data2_offset)
  1042. +- NEW_PROGRAM_H (n).p_offset += new_data2_size;
  1043. ++ NEW_PROGRAM_H (n).p_offset += new_data2_incr;
  1044. + }
  1045. + #endif
  1046. +
  1047. +@@ -675,18 +914,20 @@ unexec (new_name, old_name, data_start,
  1048. if (old_data_index == old_file_h->e_shnum)
  1049. fatal ("Can't find .data in %s.\n", old_name, 0);
  1050.  
  1051. @@ -837,17 +751,10 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1052. caddr_t src;
  1053. - /* If it is bss section, insert the new data2 section before it. */
  1054. - if (n == old_bss_index)
  1055. -+ int temp_index;
  1056. -+#ifdef HAVE_MIPS_SBSS
  1057. + /* If it is (s)bss section, insert the new data2 section before it. */
  1058. + /* new_data2_index is the index of either old_sbss or old_bss, that was
  1059. + chosen as a section for new_data2. */
  1060. -+ temp_index = new_data2_index;
  1061. -+#else /* not HAVE_MIPS_SBSS */
  1062. -+ /* If it is bss section, insert the new data2 section before it. */
  1063. -+ temp_index = old_bss_index;
  1064. -+#endif /* not HAVE_MIPS_SBSS */
  1065. -+ if (n == temp_index)
  1066. ++ if (n == new_data2_index)
  1067. {
  1068. /* Steal the data section header for this data2 section. */
  1069. memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index),
  1070. @@ -857,7 +764,7 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1071. NEW_SECTION_H (nn).sh_addr = new_data2_addr;
  1072. NEW_SECTION_H (nn).sh_offset = new_data2_offset;
  1073. NEW_SECTION_H (nn).sh_size = new_data2_size;
  1074. -@@ -696,37 +955,87 @@ unexec (new_name, old_name, data_start,
  1075. +@@ -696,73 +937,235 @@ unexec (new_name, old_name, data_start,
  1076. NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (n).sh_addralign;
  1077.  
  1078. /* Now copy over what we have in the memory now. */
  1079. @@ -873,49 +780,29 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1080. +
  1081. + memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n),
  1082. old_file_h->e_shentsize);
  1083. -
  1084. +-
  1085. - /* The new bss section's size is zero, and its file offset and virtual
  1086. - address should be off by NEW_DATA2_SIZE. */
  1087. - if (n == old_bss_index)
  1088. ++
  1089. + if (n == old_bss_index
  1090. -+#ifdef HAVE_MIPS_SBSS
  1091. + /* The new bss and sbss section's size is zero, and its file offset
  1092. + and virtual address should be off by NEW_DATA2_SIZE. */
  1093. + || n == old_sbss_index
  1094. -+#endif /* HAVE_MIPS_SBSS */
  1095. + )
  1096. {
  1097. - /* NN should be `old_bss_index + 1' at this point. */
  1098. - NEW_SECTION_H (nn).sh_offset += new_data2_size;
  1099. - NEW_SECTION_H (nn).sh_addr += new_data2_size;
  1100. +- /* NN should be `old_bss_index + 1' at this point. */
  1101. +- NEW_SECTION_H (nn).sh_offset += new_data2_size;
  1102. +- NEW_SECTION_H (nn).sh_addr += new_data2_size;
  1103. ++ /* NN should be `old_s?bss_index + 1' at this point. */
  1104. ++ NEW_SECTION_H (nn).sh_offset = new_data2_offset + new_data2_size;
  1105. ++ NEW_SECTION_H (nn).sh_addr = new_data2_addr + new_data2_size;
  1106. /* Let the new bss section address alignment be the same as the
  1107. - section address alignment followed the old bss section, so
  1108. + section address alignment followed the old bss section, so
  1109. this section will be placed in exactly the same place. */
  1110. NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (nn).sh_addralign;
  1111. NEW_SECTION_H (nn).sh_size = 0;
  1112. -+
  1113. -+#ifdef HAVE_MIPS_SBSS
  1114. -+ /* On ELF mips, the new data section replaces both .sbss and .bss
  1115. -+ (we have, after all, written to them.). Adding new_data2_size
  1116. -+ to the sh_addr and sh_offset of sbss puts sbss at the end of
  1117. -+ the new data section. setting the size to zero makes it empty.
  1118. -+ But then, adding the new_data2_size to the bss address puts
  1119. -+ its start beyond the end of the original bss. If the sbss size
  1120. -+ was bigger than a page, the bss ends up not covered by the
  1121. -+ program header. This breaks strip. Since both sbss and bss
  1122. -+ are zero-sized, just use the same address and file offset for
  1123. -+ both, guaranteeing other tools will assign them to the same
  1124. -+ program section (asssuming no sections are loaded at higher
  1125. -+ offsets.) */
  1126. -+ if (n == old_bss_index) {
  1127. -+ int new_sbss_bss_padding = NEW_SECTION_H(nn).sh_addr -
  1128. -+ NEW_SECTION_H(nn - 1).sh_addr;
  1129. -+ printf("sbss to bss offset =0x%x\n", new_sbss_bss_padding);
  1130. -+ NEW_SECTION_H(nn).sh_addr =NEW_SECTION_H(nn - 1).sh_addr;
  1131. -+ NEW_SECTION_H(nn).sh_offset =NEW_SECTION_H(nn - 1).sh_offset;
  1132. -+ }
  1133. -+#endif /* HAVE_MIPS_SBSS */
  1134. }
  1135. - /* Any section that was original placed AFTER the bss section should now
  1136. - be off by NEW_DATA2_SIZE. */
  1137. @@ -925,7 +812,12 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1138. + else
  1139. + {
  1140. + /* Any section that was original placed AFTER the bss
  1141. -+ section should now be off by NEW_DATA2_SIZE. */
  1142. ++ section should now be off by NEW_DATA2_INCR. If a
  1143. ++ section overlaps the .bss section, consider it to be
  1144. ++ placed after the .bss section. Overlap can occur if the
  1145. ++ section just before .bss has less-strict alignment; this
  1146. ++ was observed between .symtab and .bss on Solaris 2.5.1
  1147. ++ (sparc) with GCC snapshot 960602. */
  1148. +#ifdef SOLARIS_POWERPC
  1149. + /* On PPC Reference Platform running Solaris 2.5.1
  1150. + the plt section is also of type NOBI like the bss section.
  1151. @@ -937,12 +829,10 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1152. + Erik Deumens, deumens@qtp.ufl.edu. */
  1153. + if (NEW_SECTION_H (nn).sh_offset
  1154. + >= OLD_SECTION_H (old_bss_index-1).sh_offset)
  1155. -+ NEW_SECTION_H (nn).sh_offset += new_data2_size;
  1156. ++ NEW_SECTION_H (nn).sh_offset += new_data2_incr;
  1157. +#else
  1158. -+ if (round_up (NEW_SECTION_H (nn).sh_offset,
  1159. -+ OLD_SECTION_H (old_bss_index).sh_addralign)
  1160. -+ >= new_data2_offset)
  1161. -+ NEW_SECTION_H (nn).sh_offset += new_data2_size;
  1162. ++ if (NEW_SECTION_H (nn).sh_offset >= old_bss_offset)
  1163. ++ NEW_SECTION_H (nn).sh_offset += new_data2_incr;
  1164. +#endif
  1165. + /* Any section that was originally placed after the section
  1166. + header table should now be off by the size of one section
  1167. @@ -960,7 +850,20 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1168. PATCH_INDEX (NEW_SECTION_H (nn).sh_link);
  1169. /* For symbol tables, info is a symbol table index,
  1170. so don't change it. */
  1171. -@@ -738,7 +1047,7 @@ unexec (new_name, old_name, data_start,
  1172. + if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB
  1173. + && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM)
  1174. + PATCH_INDEX (NEW_SECTION_H (nn).sh_info);
  1175. ++
  1176. ++ if (old_sbss_index != -1)
  1177. ++ if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".sbss"))
  1178. ++ {
  1179. ++ NEW_SECTION_H (nn).sh_offset =
  1180. ++ round_up (NEW_SECTION_H (nn).sh_offset,
  1181. ++ NEW_SECTION_H (nn).sh_addralign);
  1182. ++ NEW_SECTION_H (nn).sh_type = SHT_PROGBITS;
  1183. ++ }
  1184. +
  1185. + /* Now, start to copy the content of sections. */
  1186. if (NEW_SECTION_H (nn).sh_type == SHT_NULL
  1187. || NEW_SECTION_H (nn).sh_type == SHT_NOBITS)
  1188. continue;
  1189. @@ -969,20 +872,39 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1190. /* Write out the sections. .data and .data1 (and data2, called
  1191. ".data" in the strings table) get copied from the current process
  1192. instead of the old file. */
  1193. -@@ -747,22 +1056,54 @@ unexec (new_name, old_name, data_start,
  1194. - || !strcmp ((old_section_names + NEW_SECTION_H(n).sh_name),
  1195. - ".sdata")
  1196. - #endif
  1197. -+#ifdef HAVE_MIPS_SBSS
  1198. + if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data")
  1199. +-#ifdef _nec_ews_svr4 /* hir, 1994.6.13 */
  1200. +- || !strcmp ((old_section_names + NEW_SECTION_H(n).sh_name),
  1201. + || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
  1202. -+ ".sdata")
  1203. + ".sdata")
  1204. + || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
  1205. + ".lit4")
  1206. + || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
  1207. + ".lit8")
  1208. -+#endif /* HAVE_MIPS_SBSS */
  1209. ++ /* The conditional bit below was in Oliva's original code
  1210. ++ (1999-08-25) and seems to have been dropped by mistake
  1211. ++ subsequently. It prevents a crash at startup under X in
  1212. ++ `IRIX64 6.5 6.5.17m' with c_dev 7.3.1.3m. It causes no
  1213. ++ trouble on the other ELF platforms I could test (Irix
  1214. ++ 6.5.15m, Solaris 8, Debian Potato x86, Debian Woody
  1215. ++ SPARC); however, it's reported to cause crashes under
  1216. ++ some version of GNU/Linux. It's not yet clear what's
  1217. ++ changed in that Irix version to cause the problem, or why
  1218. ++ the fix sometimes fails under GNU/Linux. There's
  1219. ++ probably no good reason to have something Irix-specific
  1220. ++ here, but this will have to do for now. IRIX6_5 is the
  1221. ++ most specific macro we have to test. -- fx 2002-10-01 */
  1222. ++#ifdef IRIX6_5
  1223. ++ || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
  1224. ++ ".got")
  1225. + #endif
  1226. || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
  1227. - ".data1"))
  1228. +- ".data1"))
  1229. ++ ".sdata1")
  1230. ++ || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
  1231. ++ ".data1")
  1232. ++ || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
  1233. ++ ".sbss"))
  1234. src = (caddr_t) OLD_SECTION_H (n).sh_addr;
  1235. else
  1236. src = old_base + OLD_SECTION_H (n).sh_offset;
  1237. @@ -991,18 +913,30 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1238. memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src,
  1239. NEW_SECTION_H (nn).sh_size);
  1240.  
  1241. -+#ifdef __alpha__
  1242. ++#if defined(__alpha__) && !defined(__NetBSD__)
  1243. + /* Update Alpha COFF symbol table: */
  1244. + if (strcmp (old_section_names + OLD_SECTION_H (n).sh_name, ".mdebug")
  1245. + == 0)
  1246. + {
  1247. + pHDRR symhdr = (pHDRR) (NEW_SECTION_H (nn).sh_offset + new_base);
  1248. -+ relocate_ecoff_symhdr(symhdr, new_data2_size);
  1249. ++
  1250. ++ symhdr->cbLineOffset += new_data2_size;
  1251. ++ symhdr->cbDnOffset += new_data2_size;
  1252. ++ symhdr->cbPdOffset += new_data2_size;
  1253. ++ symhdr->cbSymOffset += new_data2_size;
  1254. ++ symhdr->cbOptOffset += new_data2_size;
  1255. ++ symhdr->cbAuxOffset += new_data2_size;
  1256. ++ symhdr->cbSsOffset += new_data2_size;
  1257. ++ symhdr->cbSsExtOffset += new_data2_size;
  1258. ++ symhdr->cbFdOffset += new_data2_size;
  1259. ++ symhdr->cbRfdOffset += new_data2_size;
  1260. ++ symhdr->cbExtOffset += new_data2_size;
  1261. + }
  1262. +#endif /* __alpha__ */
  1263. +
  1264. +#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
  1265. -+ if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG && old_mdebug_index)
  1266. ++ if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG
  1267. ++ && old_mdebug_index != -1)
  1268. + {
  1269. + int diff = NEW_SECTION_H(nn).sh_offset
  1270. + - OLD_SECTION_H(old_mdebug_index).sh_offset;
  1271. @@ -1010,10 +944,75 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1272. +
  1273. + if (diff)
  1274. + {
  1275. -+ relocate_ecoff_symhdr(phdr, diff);
  1276. ++ phdr->cbLineOffset += diff;
  1277. ++ phdr->cbDnOffset += diff;
  1278. ++ phdr->cbPdOffset += diff;
  1279. ++ phdr->cbSymOffset += diff;
  1280. ++ phdr->cbOptOffset += diff;
  1281. ++ phdr->cbAuxOffset += diff;
  1282. ++ phdr->cbSsOffset += diff;
  1283. ++ phdr->cbSsExtOffset += diff;
  1284. ++ phdr->cbFdOffset += diff;
  1285. ++ phdr->cbRfdOffset += diff;
  1286. ++ phdr->cbExtOffset += diff;
  1287. + }
  1288. + }
  1289. -+#endif /* __sony_news and systype_sysv */
  1290. ++#endif /* __sony_news && _SYSTYPE_SYSV */
  1291. ++
  1292. ++#if __sgi
  1293. ++ /* Adjust the HDRR offsets in .mdebug and copy the
  1294. ++ line data if it's in its usual 'hole' in the object.
  1295. ++ Makes the new file debuggable with dbx.
  1296. ++ patches up two problems: the absolute file offsets
  1297. ++ in the HDRR record of .mdebug (see /usr/include/syms.h), and
  1298. ++ the ld bug that gets the line table in a hole in the
  1299. ++ elf file rather than in the .mdebug section proper.
  1300. ++ David Anderson. davea@sgi.com Jan 16,1994. */
  1301. ++ if (n == old_mdebug_index)
  1302. ++ {
  1303. ++#define MDEBUGADJUST(__ct,__fileaddr) \
  1304. ++ if (n_phdrr->__ct > 0) \
  1305. ++ { \
  1306. ++ n_phdrr->__fileaddr += movement; \
  1307. ++ }
  1308. ++
  1309. ++ HDRR * o_phdrr = (HDRR *)((byte *)old_base + OLD_SECTION_H (n).sh_offset);
  1310. ++ HDRR * n_phdrr = (HDRR *)((byte *)new_base + NEW_SECTION_H (nn).sh_offset);
  1311. ++ unsigned movement = new_data2_size;
  1312. ++
  1313. ++ MDEBUGADJUST (idnMax, cbDnOffset);
  1314. ++ MDEBUGADJUST (ipdMax, cbPdOffset);
  1315. ++ MDEBUGADJUST (isymMax, cbSymOffset);
  1316. ++ MDEBUGADJUST (ioptMax, cbOptOffset);
  1317. ++ MDEBUGADJUST (iauxMax, cbAuxOffset);
  1318. ++ MDEBUGADJUST (issMax, cbSsOffset);
  1319. ++ MDEBUGADJUST (issExtMax, cbSsExtOffset);
  1320. ++ MDEBUGADJUST (ifdMax, cbFdOffset);
  1321. ++ MDEBUGADJUST (crfd, cbRfdOffset);
  1322. ++ MDEBUGADJUST (iextMax, cbExtOffset);
  1323. ++ /* The Line Section, being possible off in a hole of the object,
  1324. ++ requires special handling. */
  1325. ++ if (n_phdrr->cbLine > 0)
  1326. ++ {
  1327. ++ if (o_phdrr->cbLineOffset > (OLD_SECTION_H (n).sh_offset
  1328. ++ + OLD_SECTION_H (n).sh_size))
  1329. ++ {
  1330. ++ /* line data is in a hole in elf. do special copy and adjust
  1331. ++ for this ld mistake.
  1332. ++ */
  1333. ++ n_phdrr->cbLineOffset += movement;
  1334. ++
  1335. ++ memcpy (n_phdrr->cbLineOffset + new_base,
  1336. ++ o_phdrr->cbLineOffset + old_base, n_phdrr->cbLine);
  1337. ++ }
  1338. ++ else
  1339. ++ {
  1340. ++ /* somehow line data is in .mdebug as it is supposed to be. */
  1341. ++ MDEBUGADJUST (cbLine, cbLineOffset);
  1342. ++ }
  1343. ++ }
  1344. ++ }
  1345. ++#endif /* __sgi */
  1346. +
  1347. /* If it is the symbol table, its st_shndx field needs to be patched. */
  1348. if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB
  1349. @@ -1027,7 +1026,7 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1350. new_base);
  1351. for (; num--; sym++)
  1352. {
  1353. -@@ -770,7 +1111,7 @@ unexec (new_name, old_name, data_start,
  1354. +@@ -770,7 +1173,7 @@ unexec (new_name, old_name, data_start,
  1355. || (sym->st_shndx == SHN_ABS)
  1356. || (sym->st_shndx == SHN_COMMON))
  1357. continue;
  1358. @@ -1036,7 +1035,7 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1359. PATCH_INDEX (sym->st_shndx);
  1360. }
  1361. }
  1362. -@@ -780,22 +1121,72 @@ unexec (new_name, old_name, data_start,
  1363. +@@ -780,30 +1183,101 @@ unexec (new_name, old_name, data_start,
  1364. for (n = new_file_h->e_shnum - 1; n; n--)
  1365. {
  1366. byte *symnames;
  1367. @@ -1064,6 +1063,7 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1368. memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr));
  1369. }
  1370.  
  1371. +- /* Close the files and make the new file executable. */
  1372. + /* This loop seeks out relocation sections for the data section, so
  1373. + that it can undo relocations performed by the runtime linker. */
  1374. + for (n = new_file_h->e_shnum - 1; n; n--)
  1375. @@ -1080,6 +1080,18 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1376. + nn = section.sh_info;
  1377. + if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".data")
  1378. + || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
  1379. ++ ".sdata")
  1380. ++ || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
  1381. ++ ".lit4")
  1382. ++ || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
  1383. ++ ".lit8")
  1384. ++#ifdef IRIX6_5 /* see above */
  1385. ++ || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
  1386. ++ ".got")
  1387. ++#endif
  1388. ++ || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
  1389. ++ ".sdata1")
  1390. ++ || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
  1391. + ".data1"))
  1392. + {
  1393. + ElfW(Addr) offset = NEW_SECTION_H (nn).sh_addr -
  1394. @@ -1102,15 +1114,34 @@ $NetBSD: patch-ab,v 1.3 2011/12/24 17:07
  1395. + break;
  1396. + }
  1397. + }
  1398. -+
  1399. -+#ifdef UNEXEC_USE_MAP_PRIVATE
  1400. -+ if (lseek (new_file, 0, SEEK_SET) == -1)
  1401. -+ fatal ("Can't rewind (%s): errno %d\n", new_name, errno);
  1402. +
  1403. +- if (close (old_file))
  1404. +- fatal ("Can't close (%s): errno %d\n", old_name, errno);
  1405. ++ /* Write out new_file, close it, and free the buffer containing its
  1406. ++ * contents */
  1407. +
  1408. + if (write (new_file, new_base, new_file_size) != new_file_size)
  1409. -+ fatal ("Can't write (%s): errno %d\n", new_name, errno);
  1410. ++ fatal ("Didn't write %d bytes to %s: errno %d\n",
  1411. ++ new_file_size, new_base, errno);
  1412. +
  1413. + if (close (new_file))
  1414. + fatal ("Can't close (%s): errno %d\n", new_name, errno);
  1415. +
  1416. ++ munmap (new_base, new_file_size);
  1417. ++
  1418. ++ /* Close old_file, and free the corresponding buffer */
  1419. ++
  1420. ++#if MAP_ANON == 0
  1421. ++ close (mmap_fd);
  1422. +#endif
  1423. +
  1424. - /* Close the files and make the new file executable. */
  1425. ++ if (close (old_file))
  1426. ++ fatal ("Can't close (%s): errno %d\n", old_name, errno);
  1427. ++
  1428. ++ munmap (old_base, old_file_size);
  1429. ++
  1430. ++ /* Make the new file executable */
  1431. ++
  1432. + if (stat (new_name, &stat_buf) == -1)
  1433. + fatal ("Can't stat (%s): errno %d\n", new_name, errno);
  1434.  
  1435. - if (close (old_file))
  1436. Index: patches/patch-src_alloc_c
  1437. ===================================================================
  1438. RCS file: /cvsroot/pkgsrc/editors/mule/patches/patch-src_alloc_c,v
  1439. retrieving revision 1.2
  1440. diff -u -p -d -r1.2 patch-src_alloc_c
  1441. --- patches/patch-src_alloc_c 24 Dec 2011 17:07:07 -0000 1.2
  1442. +++ patches/patch-src_alloc_c 27 Apr 2017 16:07:10 -0000
  1443. @@ -1,9 +1,6 @@
  1444. $NetBSD: patch-src_alloc_c,v 1.2 2011/12/24 17:07:07 dholland Exp $
  1445.  
  1446. - use standard includes
  1447. -- add an empty asm() destroying memory that prevents gcc from
  1448. - optimizing out __malloc_hook and friends (which leads to
  1449. - SIGSEGV in temacs during build)
  1450.  
  1451. --- src/alloc.c.orig 1994-10-24 11:37:41.000000000 +0000
  1452. +++ src/alloc.c
  1453. @@ -15,33 +12,3 @@ $NetBSD: patch-src_alloc_c,v 1.2 2011/12
  1454.  
  1455. #include <config.h>
  1456. #include "lisp.h"
  1457. -@@ -240,6 +241,9 @@ emacs_blocked_free (ptr)
  1458. - {
  1459. - BLOCK_INPUT;
  1460. - __free_hook = old_free_hook;
  1461. -+#ifdef __GNUC__
  1462. -+ __asm __volatile("":::"memory");
  1463. -+#endif
  1464. - free (ptr);
  1465. - __free_hook = emacs_blocked_free;
  1466. - UNBLOCK_INPUT;
  1467. -@@ -253,6 +257,9 @@ emacs_blocked_malloc (size)
  1468. -
  1469. - BLOCK_INPUT;
  1470. - __malloc_hook = old_malloc_hook;
  1471. -+#ifdef __GNUC__
  1472. -+ __asm __volatile("":::"memory");
  1473. -+#endif
  1474. - value = (void *) malloc (size);
  1475. - __malloc_hook = emacs_blocked_malloc;
  1476. - UNBLOCK_INPUT;
  1477. -@@ -269,6 +276,9 @@ emacs_blocked_realloc (ptr, size)
  1478. -
  1479. - BLOCK_INPUT;
  1480. - __realloc_hook = old_realloc_hook;
  1481. -+#ifdef __GNUC__
  1482. -+ __asm __volatile("":::"memory");
  1483. -+#endif
  1484. - value = (void *) realloc (ptr, size);
  1485. - __realloc_hook = emacs_blocked_realloc;
  1486. - UNBLOCK_INPUT;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement