Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. diff -r -u -N binutils-2.23.1/bfd/config.bfd kos32-binutils-2.23.1/bfd/config.bfd
  2. --- binutils-2.23.1/bfd/config.bfd      2012-09-04 18:14:59.000000000 +0400
  3. +++ kos32-binutils-2.23.1/bfd/config.bfd        2013-01-23 15:58:39.000000000 +0400
  4. @@ -512,6 +512,11 @@
  5.      targ_defvec=bfd_elf32_i386_vec
  6.      targ_selvecs=bfd_elf32_i386_vec
  7.      ;;
  8. +  i[3-7]86-*-kos32*)
  9. +    targ_defvec=i386aout_vec
  10. +    targ_selvecs="kos32_vec i386pe_vec i386pei_vec bfd_elf32_i386_vec"
  11. +    targ_underscore=yes
  12. +    ;;
  13.    i[3-7]86-*-nto*)
  14.      targ_defvec=bfd_elf32_i386_vec
  15.      targ_selvecs=i386coff_vec
  16. diff -r -u -N binutils-2.23.1/bfd/configure kos32-binutils-2.23.1/bfd/configure
  17. --- binutils-2.23.1/bfd/configure       2012-11-13 18:17:40.000000000 +0400
  18. +++ kos32-binutils-2.23.1/bfd/configure 2013-01-23 16:00:34.000000000 +0400
  19. @@ -15421,6 +15421,7 @@
  20.      icoff_big_vec)             tb="$tb coff-i960.lo cofflink.lo" ;;
  21.      icoff_little_vec)          tb="$tb coff-i960.lo cofflink.lo" ;;
  22.      ieee_vec)                  tb="$tb ieee.lo" ;;
  23. +    kos32_vec)                  tb="$tb kos32.lo" ;;
  24.      m68k4knetbsd_vec)          tb="$tb m68k4knetbsd.lo aout32.lo" ;;
  25.      m68kaux_coff_vec)          tb="$tb coff-aux.lo coff-m68k.lo cofflink.lo" ;;
  26.      m68kcoff_vec)              tb="$tb coff-m68k.lo cofflink.lo" ;;
  27. diff -r -u -N binutils-2.23.1/bfd/configure.in kos32-binutils-2.23.1/bfd/configure.in
  28. --- binutils-2.23.1/bfd/configure.in    2012-11-13 18:17:38.000000000 +0400
  29. +++ kos32-binutils-2.23.1/bfd/configure.in      2013-01-23 16:02:35.000000000 +0400
  30. @@ -913,6 +913,7 @@
  31.      icoff_big_vec)             tb="$tb coff-i960.lo cofflink.lo" ;;
  32.      icoff_little_vec)          tb="$tb coff-i960.lo cofflink.lo" ;;
  33.      ieee_vec)                  tb="$tb ieee.lo" ;;
  34. +    kos32_vec)                  tb="$tb kos32.lo" ;;
  35.      m68k4knetbsd_vec)          tb="$tb m68k4knetbsd.lo aout32.lo" ;;
  36.      m68kaux_coff_vec)          tb="$tb coff-aux.lo coff-m68k.lo cofflink.lo" ;;
  37.      m68kcoff_vec)              tb="$tb coff-m68k.lo cofflink.lo" ;;
  38. diff -r -u -N binutils-2.23.1/bfd/kos32.c kos32-binutils-2.23.1/bfd/kos32.c
  39. --- binutils-2.23.1/bfd/kos32.c 1970-01-01 03:00:00.000000000 +0300
  40. +++ kos32-binutils-2.23.1/bfd/kos32.c   2013-01-23 16:29:39.000000000 +0400
  41. @@ -0,0 +1,222 @@
  42. +/* BFD back-end for MS-DOS executables.
  43. +   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002,
  44. +   2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
  45. +   Written by Bryan Ford of the University of Utah.
  46. +
  47. +   Contributed by the Center for Software Science at the
  48. +   University of Utah (pa-gdb-bugs@cs.utah.edu).
  49. +
  50. +   This file is part of BFD, the Binary File Descriptor library.
  51. +
  52. +   This program is free software; you can redistribute it and/or modify
  53. +   it under the terms of the GNU General Public License as published by
  54. +   the Free Software Foundation; either version 3 of the License, or
  55. +   (at your option) any later version.
  56. +
  57. +   This program is distributed in the hope that it will be useful,
  58. +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  59. +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  60. +   GNU General Public License for more details.
  61. +
  62. +   You should have received a copy of the GNU General Public License
  63. +   along with this program; if not, write to the Free Software
  64. +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  65. +   MA 02110-1301, USA.  */
  66. +
  67. +
  68. +#include "sysdep.h"
  69. +#include "bfd.h"
  70. +#include "libbfd.h"
  71. +#include "libaout.h"
  72. +
  73. +#define KOS_MAGIC_0       0x554e454D
  74. +#define KOS_MAGIC_1       0x31305445
  75. +#define KOS_MAGIC_2       0x32305445
  76. +
  77. +
  78. +static int
  79. +kos32_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
  80. +                     struct bfd_link_info *info ATTRIBUTE_UNUSED)
  81. +{
  82. +  return 0;
  83. +}
  84. +
  85. +static bfd_boolean
  86. +kos32_write_object_contents (bfd *abfd)
  87. +{
  88. +  static char hdr[12];
  89. +  file_ptr outfile_size = sizeof(hdr);
  90. +  bfd_vma high_vma = 0;
  91. +  asection *sec;
  92. +
  93. +  /* Find the total size of the program on disk and in memory.  */
  94. +  for (sec = abfd->sections; sec != (asection *) NULL; sec = sec->next)
  95. +    {
  96. +      if (sec->size == 0)
  97. +        continue;
  98. +      if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
  99. +        {
  100. +         bfd_vma sec_vma = bfd_get_section_vma (abfd, sec) + sec->size;
  101. +         if (sec_vma > high_vma)
  102. +           high_vma = sec_vma;
  103. +       }
  104. +      if (bfd_get_section_flags (abfd, sec) & SEC_LOAD)
  105. +        {
  106. +         file_ptr sec_end = (sizeof (hdr)
  107. +                             + bfd_get_section_vma (abfd, sec)
  108. +                             + sec->size);
  109. +         if (sec_end > outfile_size)
  110. +           outfile_size = sec_end;
  111. +       }
  112. +    }
  113. +
  114. +  /* Make sure the program isn't too big.  */
  115. +//  if (high_vma > (bfd_vma)0xffff)
  116. +//    {
  117. +//      bfd_set_error(bfd_error_file_too_big);
  118. +//      return FALSE;
  119. +//    }
  120. +
  121. +  /* Constants.  */
  122. +  H_PUT_32 (abfd, KOS_MAGIC_0, &hdr[0]);
  123. +  H_PUT_32 (abfd, KOS_MAGIC_2, &hdr[4]);
  124. +  H_PUT_32 (abfd, 1, &hdr[8]);
  125. +
  126. +//  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
  127. +//      || bfd_bwrite (hdr, (bfd_size_type) sizeof(hdr), abfd) != sizeof(hdr))
  128. +//    return FALSE;
  129. +
  130. +  return TRUE;
  131. +}
  132. +
  133. +static bfd_boolean
  134. +kos32_set_section_contents (bfd *abfd,
  135. +                           sec_ptr section,
  136. +                           const void *location,
  137. +                           file_ptr offset,
  138. +                           bfd_size_type count)
  139. +{
  140. +
  141. +  if (count == 0)
  142. +    return TRUE;
  143. +
  144. +  section->filepos = bfd_get_section_vma (abfd, section);
  145. +
  146. +  if (bfd_get_section_flags (abfd, section) & SEC_LOAD)
  147. +    {
  148. +      if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
  149. +          || bfd_bwrite (location, count, abfd) != count)
  150. +        return FALSE;
  151. +    }
  152. +
  153. +  return TRUE;
  154. +}
  155. +
  156. +static bfd_boolean
  157. +kos32_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
  158. +{
  159. +  return TRUE;
  160. +}
  161. +
  162. +
  163. +#define kos32_make_empty_symbol _bfd_generic_make_empty_symbol
  164. +#define kos32_bfd_reloc_type_lookup aout_32_reloc_type_lookup
  165. +#define kos32_bfd_reloc_name_lookup aout_32_reloc_name_lookup
  166. +
  167. +#define kos32_close_and_cleanup _bfd_generic_close_and_cleanup
  168. +#define kos32_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
  169. +#define kos32_new_section_hook _bfd_generic_new_section_hook
  170. +#define kos32_get_section_contents _bfd_generic_get_section_contents
  171. +#define kos32_get_section_contents_in_window \
  172. +  _bfd_generic_get_section_contents_in_window
  173. +#define kos32_bfd_get_relocated_section_contents \
  174. +  bfd_generic_get_relocated_section_contents
  175. +#define kos32_bfd_relax_section bfd_generic_relax_section
  176. +#define kos32_bfd_gc_sections bfd_generic_gc_sections
  177. +#define kos32_bfd_lookup_section_flags bfd_generic_lookup_section_flags
  178. +#define kos32_bfd_merge_sections bfd_generic_merge_sections
  179. +#define kos32_bfd_is_group_section bfd_generic_is_group_section
  180. +#define kos32_bfd_discard_group bfd_generic_discard_group
  181. +#define kos32_section_already_linked \
  182. +  _bfd_generic_section_already_linked
  183. +#define kos32_bfd_define_common_symbol bfd_generic_define_common_symbol
  184. +#define kos32_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  185. +#define kos32_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
  186. +#define kos32_bfd_link_add_symbols _bfd_generic_link_add_symbols
  187. +#define kos32_bfd_link_just_syms _bfd_generic_link_just_syms
  188. +#define kos32_bfd_copy_link_hash_symbol_type \
  189. +        _bfd_generic_copy_link_hash_symbol_type
  190. +#define kos32_bfd_final_link _bfd_generic_final_link
  191. +#define kos32_bfd_link_split_section _bfd_generic_link_split_section
  192. +#define kos32_set_arch_mach _bfd_generic_set_arch_mach
  193. +
  194. +#define kos32_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
  195. +#define kos32_canonicalize_symtab _bfd_nosymbols_canonicalize_symtab
  196. +#define kos32_print_symbol _bfd_nosymbols_print_symbol
  197. +#define kos32_get_symbol_info _bfd_nosymbols_get_symbol_info
  198. +#define kos32_find_nearest_line _bfd_nosymbols_find_nearest_line
  199. +#define kos32_find_inliner_info _bfd_nosymbols_find_inliner_info
  200. +#define kos32_get_lineno _bfd_nosymbols_get_lineno
  201. +#define kos32_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
  202. +#define kos32_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
  203. +#define kos32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  204. +#define kos32_read_minisymbols _bfd_nosymbols_read_minisymbols
  205. +#define kos32_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
  206. +
  207. +#define kos32_canonicalize_reloc _bfd_norelocs_canonicalize_reloc
  208. +#define kos32_get_reloc_upper_bound _bfd_norelocs_get_reloc_upper_bound
  209. +#define kos32_32_bfd_link_split_section  _bfd_generic_link_split_section
  210. +
  211. +const bfd_target kos32_vec =
  212. +  {
  213. +    "kos32",           /* name */
  214. +    bfd_target_msdos_flavour,
  215. +    BFD_ENDIAN_LITTLE,         /* target byte order */
  216. +    BFD_ENDIAN_LITTLE,         /* target headers byte order */
  217. +    (EXEC_P),                  /* object flags */
  218. +    (SEC_CODE | SEC_DATA | SEC_HAS_CONTENTS
  219. +     | SEC_ALLOC | SEC_LOAD),  /* section flags */
  220. +    0,                         /* leading underscore */
  221. +    ' ',                               /* ar_pad_char */
  222. +    16,                                /* ar_max_namelen */
  223. +    0,                          /* match priority */
  224. +    bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  225. +    bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  226. +    bfd_getl16, bfd_getl_signed_16, bfd_putl16,        /* data */
  227. +    bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  228. +    bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  229. +    bfd_getl16, bfd_getl_signed_16, bfd_putl16,        /* hdrs */
  230. +
  231. +    {
  232. +      _bfd_dummy_target,
  233. +      _bfd_dummy_target,               /* bfd_check_format */
  234. +      _bfd_dummy_target,
  235. +      _bfd_dummy_target,
  236. +    },
  237. +    {
  238. +      bfd_false,
  239. +      kos32_mkobject,
  240. +      _bfd_generic_mkarchive,
  241. +      bfd_false,
  242. +    },
  243. +    {                          /* bfd_write_contents */
  244. +      bfd_false,
  245. +      kos32_write_object_contents,
  246. +      _bfd_write_archive_contents,
  247. +      bfd_false,
  248. +    },
  249. +
  250. +    BFD_JUMP_TABLE_GENERIC (kos32),
  251. +    BFD_JUMP_TABLE_COPY (_bfd_generic),
  252. +    BFD_JUMP_TABLE_CORE (_bfd_nocore),
  253. +    BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  254. +    BFD_JUMP_TABLE_SYMBOLS (kos32),
  255. +    BFD_JUMP_TABLE_RELOCS (kos32),
  256. +    BFD_JUMP_TABLE_WRITE (kos32),
  257. +    BFD_JUMP_TABLE_LINK (kos32),
  258. +    BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  259. +
  260. +    NULL,
  261. +
  262. +    (PTR) 0
  263. +  };
  264. diff -r -u -N binutils-2.23.1/bfd/targets.c kos32-binutils-2.23.1/bfd/targets.c
  265. --- binutils-2.23.1/bfd/targets.c       2012-09-04 16:53:42.000000000 +0400
  266. +++ kos32-binutils-2.23.1/bfd/targets.c 2013-01-23 16:06:37.000000000 +0400
  267. @@ -806,6 +806,7 @@
  268.  extern const bfd_target icoff_big_vec;
  269.  extern const bfd_target icoff_little_vec;
  270.  extern const bfd_target ieee_vec;
  271. +extern const bfd_target kos32_vec;
  272.  extern const bfd_target m68k4knetbsd_vec;
  273.  extern const bfd_target m68kaux_coff_vec;
  274.  extern const bfd_target m68kcoff_vec;
  275. diff -r -u -N binutils-2.23.1/config.sub kos32-binutils-2.23.1/config.sub
  276. --- binutils-2.23.1/config.sub  2012-04-25 19:53:25.000000000 +0400
  277. +++ kos32-binutils-2.23.1/config.sub    2013-01-23 16:07:13.000000000 +0400
  278. @@ -1368,7 +1368,7 @@
  279.               | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
  280.               | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
  281.               | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
  282. -             | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
  283. +             | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es | -kos32*)
  284.         # Remember, each alternative MUST END IN *, to match a version number.
  285.                 ;;
  286.         -qnx*)
  287. diff -r -u -N binutils-2.23.1/gas/configure.tgt kos32-binutils-2.23.1/gas/configure.tgt
  288. --- binutils-2.23.1/gas/configure.tgt   2012-09-04 16:53:45.000000000 +0400
  289. +++ kos32-binutils-2.23.1/gas/configure.tgt     2013-01-23 16:08:33.000000000 +0400
  290. @@ -238,6 +238,7 @@
  291.    i386-*-pe)                           fmt=coff em=pe ;;
  292.    i386-*-cygwin*)                      fmt=coff em=pe ;;
  293.    i386-*-interix*)                     fmt=coff em=interix ;;
  294. +  i386-*-kos32*)                        fmt=coff em=pe ;;
  295.    i386-*-mingw*)
  296.      case ${cpu} in
  297.        x86_64*)                         fmt=coff em=pep ;;
  298. diff -r -u -N binutils-2.23.1/ld/configure.tgt kos32-binutils-2.23.1/ld/configure.tgt
  299. --- binutils-2.23.1/ld/configure.tgt    2012-09-04 16:53:47.000000000 +0400
  300. +++ kos32-binutils-2.23.1/ld/configure.tgt      2013-01-23 16:12:11.000000000 +0400
  301. @@ -299,6 +299,7 @@
  302.  x86_64-*-mingw*)       targ_emul=i386pep ;
  303.                         targ_extra_emuls=i386pe
  304.                         targ_extra_ofiles="deffilep.o pep-dll.o pe-dll.o" ;;
  305. +i[3-7]86-*-kos32*)      targ_emul=kos32 ;;
  306.  i[3-7]86-*-interix*)   targ_emul=i386pe_posix;
  307.                         targ_extra_ofiles="deffilep.o pe-dll.o" ;;
  308.  i[3-7]86-*-beospe*)    targ_emul=i386beos ;;
  309. diff -r -u -N binutils-2.23.1/ld/emulparams/kos32.sh kos32-binutils-2.23.1/ld/emulparams/kos32.sh
  310. --- binutils-2.23.1/ld/emulparams/kos32.sh      1970-01-01 03:00:00.000000000 +0300
  311. +++ kos32-binutils-2.23.1/ld/emulparams/kos32.sh        2013-01-23 16:13:36.000000000 +0400
  312. @@ -0,0 +1,8 @@
  313. +ARCH=i386
  314. +SCRIPT_NAME=kos32
  315. +OUTPUT_FORMAT="kos32"
  316. +TEMPLATE_NAME=kos32
  317. +ENTRY="__start"
  318. +INITIAL_SYMBOL_CHAR=\"_\"
  319. +NOP=0x90909090
  320. +TARGET_PAGE_SIZE=0x1000
  321. diff -r -u -N binutils-2.23.1/ld/emultempl/kos32.em kos32-binutils-2.23.1/ld/emultempl/kos32.em
  322. --- binutils-2.23.1/ld/emultempl/kos32.em       1970-01-01 03:00:00.000000000 +0300
  323. +++ kos32-binutils-2.23.1/ld/emultempl/kos32.em 2013-01-23 16:57:01.000000000 +0400
  324. @@ -0,0 +1,246 @@
  325. +# This shell script emits a C file. -*- C -*-
  326. +#   Copyright 2007 Free Software Foundation, Inc.
  327. +#
  328. +# This file is part of the GNU Binutils.
  329. +#
  330. +# This program is free software; you can redistribute it and/or modify
  331. +# it under the terms of the GNU General Public License as published by
  332. +# the Free Software Foundation; either version 3 of the License, or
  333. +# (at your option) any later version.
  334. +#
  335. +# This program is distributed in the hope that it will be useful,
  336. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  337. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  338. +# GNU General Public License for more details.
  339. +#
  340. +# You should have received a copy of the GNU General Public License
  341. +# along with this program; if not, write to the Free Software
  342. +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  343. +# MA 02110-1301, USA.
  344. +#
  345. +
  346. +fragment <<EOF
  347. +
  348. +#include "sysdep.h"
  349. +#include "bfd.h"
  350. +#include "bfdlink.h"
  351. +#include "getopt.h"
  352. +#include "libiberty.h"
  353. +#include "ld.h"
  354. +#include "ldmain.h"
  355. +#include "ldexp.h"
  356. +#include "ldlang.h"
  357. +#include "ldfile.h"
  358. +#include "ldemul.h"
  359. +#include <ldgram.h>
  360. +#include "ldlex.h"
  361. +#include "ldmisc.h"
  362. +#include "ldctor.h"
  363. +#include "coff/internal.h"
  364. +
  365. +/* FIXME: See bfd/peXXigen.c for why we include an architecture specific
  366. +   header in generic PE code.  */
  367. +#include "coff/i386.h"
  368. +#include "coff/pe.h"
  369. +
  370. +/* FIXME: This is a BFD internal header file, and we should not be
  371. +   using it here.  */
  372. +#include "../bfd/libcoff.h"
  373. +
  374. +#include "deffile.h"
  375. +#include "pe-dll.h"
  376. +#include "safe-ctype.h"
  377. +
  378. +static struct internal_extra_pe_aouthdr pe;
  379. +
  380. +static void
  381. +gld_${EMULATION_NAME}_before_parse (void)
  382. +{
  383. +  ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
  384. +  config.has_shared = FALSE;
  385. +}
  386. +
  387. +
  388. +#define OPTION_STACK                   (300 + 1)
  389. +
  390. +static void
  391. +gld_${EMULATION_NAME}_add_options
  392. +  (int ns ATTRIBUTE_UNUSED,
  393. +   char **shortopts ATTRIBUTE_UNUSED,
  394. +   int nl,
  395. +   struct option **longopts,
  396. +   int nrl ATTRIBUTE_UNUSED,
  397. +   struct option **really_longopts ATTRIBUTE_UNUSED)
  398. +{
  399. +  static const struct option xtra_long[] = {
  400. +    /* KOS32 options */
  401. +    {"stack", required_argument, NULL, OPTION_STACK},
  402. +    {NULL, no_argument, NULL, 0}
  403. +  };
  404. +
  405. +  *longopts
  406. +    = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
  407. +  memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
  408. +}
  409. +
  410. +typedef struct
  411. +{
  412. +  void *ptr;
  413. +  int size;
  414. +  int value;
  415. +  char *symbol;
  416. +  int inited;
  417. +} definfo;
  418. +
  419. +#define D(field,symbol,def)  {&pe.field,sizeof(pe.field), def, symbol,0}
  420. +
  421. +
  422. +static definfo init[] =
  423. +{
  424. +  D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000),
  425. +  { NULL, 0, 0, NULL, 0 }
  426. +};
  427. +
  428. +static void
  429. +gld_${EMULATION_NAME}_list_options (FILE *file)
  430. +{
  431. +  fprintf (file, _("  --stack <size>                     Set size of the stack\n"));
  432. +}
  433. +
  434. +static void
  435. +set_pe_name (char *name, long val)
  436. +{
  437. +  int i;
  438. +
  439. +  /* Find the name and set it.  */
  440. +  for (i = 0; init[i].ptr; i++)
  441. +    {
  442. +      if (strcmp (name, init[i].symbol) == 0)
  443. +        {
  444. +          init[i].value = val;
  445. +          init[i].inited = 1;
  446. +          return;
  447. +        }
  448. +    }
  449. +  abort ();
  450. +}
  451. +
  452. +static void
  453. +set_pe_value (char *name)
  454. +{
  455. +  char *end;
  456. +
  457. +  set_pe_name (name,  strtoul (optarg, &end, 0));
  458. +
  459. +  if (end == optarg)
  460. +    einfo (_("%P%F: invalid hex number for KOS32 parameter '%s'\n"), optarg);
  461. +
  462. +  optarg = end;
  463. +}
  464. +
  465. +static void
  466. +gld_${EMULATION_NAME}_set_symbols (void)
  467. +{
  468. +  /* Run through and invent symbols for all the
  469. +     names and insert the defaults. */
  470. +  int j;
  471. +
  472. +  /* Glue the assignments into the abs section */
  473. +  push_stat_ptr (&abs_output_section->children);
  474. +
  475. +  for (j = 0; init[j].ptr; j++)
  476. +    {
  477. +      long val = init[j].value;
  478. +      lang_add_assignment (exp_assign (init[j].symbol, exp_intop (val), FALSE));
  479. +      if (init[j].size == sizeof(short))
  480. +        *(short *)init[j].ptr = val;
  481. +      else if (init[j].size == sizeof(int))
  482. +        *(int *)init[j].ptr = val;
  483. +      else if (init[j].size == sizeof(long))
  484. +        *(long *)init[j].ptr = val;
  485. +      /* This might be a long long or other special type.  */
  486. +      else if (init[j].size == sizeof(bfd_vma))
  487. +        *(bfd_vma *)init[j].ptr = val;
  488. +      else      abort();
  489. +    }
  490. +  /* Restore the pointer. */
  491. +  pop_stat_ptr ();
  492. +}
  493. +
  494. +static bfd_boolean
  495. +gld_${EMULATION_NAME}_handle_option (int optc)
  496. +{
  497. +  switch (optc)
  498. +  {
  499. +    default:
  500. +      return FALSE;
  501. +
  502. +      /* PE options.  */
  503. +    case OPTION_STACK:
  504. +      set_pe_value ("__size_of_stack_reserve__");
  505. +      break;
  506. +  }
  507. +  return TRUE;
  508. +}
  509. +
  510. +static char *
  511. +gld_${EMULATION_NAME}_get_script (int *isfile)
  512. +EOF
  513. +# Scripts compiled in.
  514. +# sed commands to quote an ld script as a C string.
  515. +sc="-f stringify.sed"
  516. +
  517. +fragment <<EOF
  518. +{
  519. +  *isfile = 0;
  520. +
  521. +  if (link_info.relocatable && config.build_constructors)
  522. +    return
  523. +EOF
  524. +sed $sc ldscripts/${EMULATION_NAME}.xu                  >> e${EMULATION_NAME}.c
  525. +echo '  ; else if (link_info.relocatable) return'       >> e${EMULATION_NAME}.c
  526. +sed $sc ldscripts/${EMULATION_NAME}.xr                  >> e${EMULATION_NAME}.c
  527. +echo '  ; else if (!config.text_read_only) return'      >> e${EMULATION_NAME}.c
  528. +sed $sc ldscripts/${EMULATION_NAME}.xbn                 >> e${EMULATION_NAME}.c
  529. +echo '  ; else if (!config.magic_demand_paged) return'  >> e${EMULATION_NAME}.c
  530. +sed $sc ldscripts/${EMULATION_NAME}.xn                  >> e${EMULATION_NAME}.c
  531. +if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
  532. +echo '  ; else if (link_info.pei386_auto_import == 1) return'   >> e${EMULATION_NAME}.c
  533. +sed $sc ldscripts/${EMULATION_NAME}.xa                  >> e${EMULATION_NAME}.c
  534. +fi
  535. +echo '  ; else return'                                  >> e${EMULATION_NAME}.c
  536. +sed $sc ldscripts/${EMULATION_NAME}.x                   >> e${EMULATION_NAME}.c
  537. +echo '; }'                                              >> e${EMULATION_NAME}.c
  538. +
  539. +fragment <<EOF
  540. +
  541. +
  542. +struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
  543. +{
  544. +  gld_${EMULATION_NAME}_before_parse,
  545. +  syslib_default,
  546. +  hll_default,
  547. +  after_parse_default,
  548. +  after_open_default,
  549. +  after_allocation_default,
  550. +  set_output_arch_default,
  551. +  ldemul_default_target,
  552. +  before_allocation_default,
  553. +  gld_${EMULATION_NAME}_get_script,
  554. +  "${EMULATION_NAME}",
  555. +  "${OUTPUT_FORMAT}",
  556. +  finish_default,
  557. +  NULL, /* Create output section statements.  */
  558. +  NULL, /* open dynamic archive */
  559. +  NULL,
  560. +  gld_${EMULATION_NAME}_set_symbols,
  561. +  NULL, /* parse_args */
  562. +  gld_${EMULATION_NAME}_add_options,
  563. +  gld_${EMULATION_NAME}_handle_option,
  564. +  NULL,
  565. +  gld_${EMULATION_NAME}_list_options,
  566. +  NULL,
  567. +  NULL, /* find_potential_libraries */
  568. +  NULL  /* new_vers_pattern.  */
  569. +};
  570. +EOF
  571. diff -r -u -N binutils-2.23.1/ld/Makefile.in kos32-binutils-2.23.1/ld/Makefile.in
  572. --- binutils-2.23.1/ld/Makefile.in      2012-09-04 16:53:47.000000000 +0400
  573. +++ kos32-binutils-2.23.1/ld/Makefile.in        2013-01-23 16:11:11.000000000 +0400
  574. @@ -619,6 +619,7 @@
  575.         ei386pe.c \
  576.         ei386pe_posix.c \
  577.         ei386pep.c \
  578. +       ekos32.c \
  579.         elnk960.c \
  580.         em32relf.c \
  581.         em32relf_linux.c \
  582. @@ -2853,6 +2854,9 @@
  583.  ei386pep.c: $(srcdir)/emulparams/i386pep.sh \
  584.    $(srcdir)/emultempl/pep.em $(srcdir)/scripttempl/pep.sc ${GEN_DEPENDS}
  585.         ${GENSCRIPTS} i386pep "$(tdir_i386pe)"
  586. +ekos32.c: $(srcdir)/emulparams/kos32.sh \
  587. + $(srcdir)/emultempl/kos32.em $(srcdir)/scripttempl/kos32.sc ${GEN_DEPENDS}
  588. +       ${GENSCRIPTS} kos32 "$(tdir_kos32)"
  589.  elnk960.c: $(srcdir)/emulparams/lnk960.sh \
  590.    $(srcdir)/emultempl/lnk960.em $(srcdir)/scripttempl/i960.sc ${GEN_DEPENDS}
  591.         ${GENSCRIPTS} lnk960 "$(tdir_lnk960)"
  592. diff -r -u -N binutils-2.23.1/ld/scripttempl/kos32.sc kos32-binutils-2.23.1/ld/scripttempl/kos32.sc
  593. --- binutils-2.23.1/ld/scripttempl/kos32.sc     1970-01-01 03:00:00.000000000 +0300
  594. +++ kos32-binutils-2.23.1/ld/scripttempl/kos32.sc       2013-01-23 17:47:19.000000000 +0400
  595. @@ -0,0 +1,117 @@
  596. +cat <<EOF
  597. +OUTPUT_FORMAT("${OUTPUT_FORMAT}")
  598. +OUTPUT_ARCH("${OUTPUT_ARCH}")
  599. +ENTRY(__start)
  600. +SECTIONS
  601. +{
  602. +    .text 0x000000:
  603. +    {
  604. +        LONG(0x554e454D);
  605. +        LONG(0x32305445);
  606. +        LONG(1);
  607. +        LONG(__start);
  608. +        LONG(___iend);
  609. +        LONG(___memsize);
  610. +        LONG(___stacktop);
  611. +        LONG(___cmdline);
  612. +        LONG(___pgmname);     /*  full path    */
  613. +        LONG(0);              /*FIXME tls data */
  614. +
  615. +        *(.init)
  616. +        *(.text)
  617. +        *(SORT(.text$*))
  618. +        *(.text.*)
  619. +        *(.glue_7t)
  620. +        *(.glue_7)
  621. +        ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
  622. +                        LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);
  623. +        ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
  624. +                        LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0);
  625. +        *(.fini)
  626. +    /* ??? Why is .gcc_exc here?  */
  627. +        *(.gcc_exc)
  628. +        PROVIDE (etext = .);
  629. +        *(.gcc_except_table)
  630. +    }
  631. +
  632. +    .rdata ALIGN(16) :
  633. +    {
  634. +        *(.rdata)
  635. +        *(SORT(.rdata$*))
  636. +        ___RUNTIME_PSEUDO_RELOC_LIST__ = .;
  637. +        __RUNTIME_PSEUDO_RELOC_LIST__ = .;
  638. +        *(.rdata_runtime_pseudo_reloc)
  639. +        ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
  640. +        __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
  641. +    }
  642. +    .CRT ALIGN(16) :
  643. +    {
  644. +         ___crt_xc_start__ = . ;
  645. +        *(SORT(.CRT$XC*))  /* C initialization */
  646. +        ___crt_xc_end__ = . ;
  647. +        ___crt_xi_start__ = . ;
  648. +        *(SORT(.CRT$XI*))  /* C++ initialization */
  649. +        ___crt_xi_end__ = . ;
  650. +        ___crt_xl_start__ = . ;
  651. +        *(SORT(.CRT$XL*))  /* TLS callbacks */
  652. +    /* ___crt_xl_end__ is defined in the TLS Directory support code */
  653. +        ___crt_xp_start__ = . ;
  654. +        *(SORT(.CRT$XP*))  /* Pre-termination */
  655. +        ___crt_xp_end__ = . ;
  656. +        ___crt_xt_start__ = . ;
  657. +        *(SORT(.CRT$XT*))  /* Termination */
  658. +        ___crt_xt_end__ = . ;
  659. +    }
  660. +
  661. +    .data ALIGN(16) :
  662. +    {
  663. +        __data_start__ = . ;
  664. +        *(.data)
  665. +        *(.data2)
  666. +        *(SORT(.data$*))
  667. +        *(.jcr)
  668. +        __CRT_MT = .;
  669. +        LONG(0);
  670. +        __data_end__ = . ;
  671. +        *(.data_cygwin_nocopy)
  672. +    }
  673. +
  674. +    .eh_frame ALIGN(16) :
  675. +    {
  676. +        *(.eh_frame)
  677. +        ___iend = . ;
  678. +    }
  679. +
  680. +    bss ALIGN(16):
  681. +    {
  682. +        *(.bss)
  683. +        *(COMMON)
  684. +        . = ALIGN(16);
  685. +        ___cmdline = .;
  686. +        . = . + 256;
  687. +        ___pgmname = .;
  688. +        . = . + 1024 + 16;
  689. +        ___stacktop = .;
  690. +        ___memsize = . ;
  691. +    }
  692. +
  693. +  /DISCARD/ :
  694. +  {
  695. +    *(.debug$S)
  696. +    *(.debug$T)
  697. +    *(.debug$F)
  698. +    *(.drectve)
  699. +    *(.note.GNU-stack)
  700. +    *(.comment)
  701. +    *(.debug_abbrev)
  702. +    *(.debug_info)
  703. +    *(.debug_line)
  704. +    *(.debug_frame)
  705. +    *(.debug_loc)
  706. +    *(.debug_pubnames)
  707. +    *(.debug_aranges)
  708. +    *(.debug_ranges)
  709. +  }
  710. +
  711. +}
  712. +EOF
  713.