diff options
author | Steve Chamberlain <sac@cygnus> | 1995-05-12 18:55:06 +0000 |
---|---|---|
committer | Steve Chamberlain <sac@cygnus> | 1995-05-12 18:55:06 +0000 |
commit | 3f38a017be911b803f3a06d86dc77db6ccecc9f0 (patch) | |
tree | 8bfc5c87d9ec292e6916a376506d6a28b5f3a243 /ld | |
parent | 48b2d07e4c59bbbaacf6face47e2eafac2271092 (diff) | |
download | gdb-3f38a017be911b803f3a06d86dc77db6ccecc9f0.zip gdb-3f38a017be911b803f3a06d86dc77db6ccecc9f0.tar.gz gdb-3f38a017be911b803f3a06d86dc77db6ccecc9f0.tar.bz2 |
Fri May 12 11:03:55 1995 Steve Chamberlain <sac@slash.cygnus.com>
Tom Griest <griest@cs.yale.edu>
Initial support for PE executables (eg NT, win32)
* Makefile.in (configure.in, ei386pe): Add support.
* ldmain.c (main): Initialize PE argument info.
* ldwrite.c (print_file_stuff): Don't print out .drectve
and .debug section info.
* lexsup.c (set_subsystem, set_stack_heap, OPTION_HEAP,
OPTION_SUBSYSTEM, parse_argsm set_subsystem, set_stack_heap):
Handle new arguments.
* config/i386-pe.mt, emultempl/i386pe.em, scripttempl/i386pe.sc:
New files
Diffstat (limited to 'ld')
-rw-r--r-- | ld/config/.Sanitize | 17 | ||||
-rw-r--r-- | ld/config/i386-pe.mt | 1 | ||||
-rw-r--r-- | ld/emulparams/.Sanitize | 5 | ||||
-rw-r--r-- | ld/emulparams/i386pe.sh | 3 | ||||
-rw-r--r-- | ld/emultempl/.Sanitize | 3 | ||||
-rw-r--r-- | ld/emultempl/i386pe.em | 230 | ||||
-rw-r--r-- | ld/ldlang.c | 23 | ||||
-rw-r--r-- | ld/scripttempl/.Sanitize | 1 | ||||
-rw-r--r-- | ld/scripttempl/i386pe.sc | 95 |
9 files changed, 367 insertions, 11 deletions
diff --git a/ld/config/.Sanitize b/ld/config/.Sanitize index b83a01e..d0e688c 100644 --- a/ld/config/.Sanitize +++ b/ld/config/.Sanitize @@ -41,17 +41,18 @@ Things-to-keep: alpha.mt alphaosf.mh +cf-h8300h.mt coff-a29k.mt coff-h8300.mt -cf-h8300h.mt coff-h8500.mt coff-sh.mt coff-sparc.mt +coff-w65.mt delta88.mh dgux.mh ebmon29k.mt -go32.mt go32.mh +go32.mt hp300.mh hp300bsd.mt hp300hpux.mt @@ -70,6 +71,7 @@ i386-lynx.mt i386-mach.mt i386-nbsd.mt i386-nw.mt +i386-pe.mt i386bsd.mh i386linux.mh i386lynx.mh @@ -82,21 +84,21 @@ i960coff.mt ieee-h8300.mt irix4.mh m68k-coff.mt -m68k.mt m68k-elf.mt m68k-lynx.mt m68k-nbsd.mt +m68k.mt m68klynx.mh m68kv.mt m88k-bcs.mt -mipsbsd.mh -mipsbsd.mt mips-big.mt mips-idt.mt +mips-lit.mt mipsb-elf32.mt +mipsbsd.mh +mipsbsd.mt mipsl-elf32.mt mipsl-idt.mt -mips-lit.mt news.mt ns32k-nbsd.mt ose68.mt @@ -108,10 +110,10 @@ riscix.mt rtbsd.mh sa29200.mt solaris2.mh -sparc64-elf.mt sparc-ll.mh sparc-lynx.mt sparc-nbsd.mt +sparc64-elf.mt st2000.mt sun3.mh sun3.mt @@ -121,7 +123,6 @@ vax.mt vsta.mt vxworks68.mt z8ksim.mt -coff-w65.mt Things-to-lose: diff --git a/ld/config/i386-pe.mt b/ld/config/i386-pe.mt new file mode 100644 index 0000000..10d7f83 --- /dev/null +++ b/ld/config/i386-pe.mt @@ -0,0 +1 @@ +EMUL=i386pe diff --git a/ld/emulparams/.Sanitize b/ld/emulparams/.Sanitize index b17b1af..326cd9f 100644 --- a/ld/emulparams/.Sanitize +++ b/ld/emulparams/.Sanitize @@ -45,10 +45,10 @@ alpha.sh coff_sparc.sh ebmon29k.sh elf32_sparc.sh -elf64_sparc.sh elf32bmip.sh elf32lmip.sh elf32ppc.sh +elf64_sparc.sh elf32ppcle.sh elf_i386.sh gld960.sh @@ -59,8 +59,8 @@ h8300h.sh h8500.sh h8500b.sh h8500c.sh -h8500s.sh h8500m.sh +h8500s.sh hp300bsd.sh hp3hpux.sh hppaelf.sh @@ -73,6 +73,7 @@ i386lynx.sh i386mach.sh i386nbsd.sh i386nw.sh +i386pe.sh lnk960.sh m68kaout.sh m68kcoff.sh diff --git a/ld/emulparams/i386pe.sh b/ld/emulparams/i386pe.sh new file mode 100644 index 0000000..df2e9d8 --- /dev/null +++ b/ld/emulparams/i386pe.sh @@ -0,0 +1,3 @@ +ARCH=i386 +SCRIPT_NAME=i386pe +OUTPUT_FORMAT="pe-i386" diff --git a/ld/emultempl/.Sanitize b/ld/emultempl/.Sanitize index 8080c68..e86e204 100644 --- a/ld/emultempl/.Sanitize +++ b/ld/emultempl/.Sanitize @@ -25,16 +25,17 @@ Do-first: Things-to-keep: README -stringify.sed elf32.em generic.em gld960.em gld960c.em hppaelf.em +i386pe.em linux.em lnk960.em m88kbcs.em mipsecoff.em +stringify.sed sunos.em vanilla.em diff --git a/ld/emultempl/i386pe.em b/ld/emultempl/i386pe.em new file mode 100644 index 0000000..a27ed40 --- /dev/null +++ b/ld/emultempl/i386pe.em @@ -0,0 +1,230 @@ +# This shell script emits a C file. -*- C -*- +# It does some substitutions. +cat >e${EMULATION_NAME}.c <<EOF +/* For WINDOWS_NT */ +/* This file is a copy of ei385coff which was originally generated on a Linux + system. It has been modified to provide a decent default script file + for the NT PE format. */ + +/* The original file generated returned different default scripts depending + on whether certain switches were set, but these switches pertain to the + Linux system and that particular version of coff. In the NT case, we + only determine if the subsystem is console or windows in order to select + the correct entry point by default. */ + + +/* emulate the original gld for the given i386pe + Copyright (C) 1991, 1993 Free Software Foundation, Inc. + Written by Steve Chamberlain steve@cygnus.com + +This file is part of GLD, the Gnu Linker. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#define TARGET_IS_i386pe + +#include "bfd.h" +#include "sysdep.h" +#include "bfdlink.h" + +#include "ld.h" +#include "config.h" +#include "ldmain.h" +#include "ldemul.h" +#include "ldfile.h" +#include "ldmisc.h" + +static void gldi386pe_before_parse PARAMS ((void)); +static char *gldi386pe_get_script PARAMS ((int *isfile)); + +static void +gldi386pe_before_parse() +{ +#ifndef TARGET_ /* I.e., if not generic. */ + ldfile_output_architecture = bfd_arch_i386; +#endif /* not TARGET_ */ +} + +static char * +gldi386pe_get_script(isfile) + int *isfile; +{ + *isfile = 0; + + if (link_info.subsystem == windows) + return +"OUTPUT_FORMAT(\"coff-i386\")\n\ +SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/local/i386-coff/lib);\n\ +ENTRY(_WinMainCRTStartup)\n\ +SECTIONS\n\ +{\n\ + .text 0x401000 : {\n\ + *(.text)\n\ + ;\n\ + }\n\ + .bss BLOCK(0x1000) :\n\ + { \n\ + *(.bss)\n\ + *(COMMON)\n\ + ;\n\ + }\n\ + .rdata BLOCK(0x1000) :\n\ + { \n\ + *(.rdata)\n\ + ;\n\ + }\n\ + .data BLOCK(0x1000) : {\n\ + *(.data)\n\ + *(.data2)\n\ + ;\n\ + }\n\ + .idata BLOCK(0x1000) :\n\ + { \n\ + *(.idata$2)\n\ + *(.idata$3)\n\ + *(.idata$4)\n\ + *(.idata$5)\n\ + *(.idata$6)\n\ + *(.idata$7)\n\ + ;\n\ + }\n\ + .CRT BLOCK(0x1000) :\n\ + { \n\ + *(.CRT$XCA)\n\ + *(.CRT$XCC)\n\ + *(.CRT$XCZ)\n\ + *(.CRT$XIA)\n\ + *(.CRT$XIC)\n\ + *(.CRT$XIZ)\n\ + *(.CRT$XLA)\n\ + *(.CRT$XLZ)\n\ + *(.CRT$XPA)\n\ + *(.CRT$XPX)\n\ + *(.CRT$XPZ)\n\ + *(.CRT$XTA)\n\ + *(.CRT$XTZ)\n\ + ;\n\ + }\n\ + .rsrc BLOCK(0x1000) :\n\ + { \n\ + *(.rsrc$01)\n\ + *(.rsrc$02)\n\ + ;\n\ + }\n\ + .reloc BLOCK(0x1000) :\n\ + { \n\ + *(.reloc)\n\ + ;\n\ + }\n\ + .junk BLOCK(0x1000) :\n\ + { \n\ + *(.debug$S)\n\ + *(.debug$T)\n\ + *(.debug$F)\n\ + *(.drectve)\n\ + ;\n\ + }\n\ +}\n\n" + ; else return +"OUTPUT_FORMAT(\"coff-i386\")\n\ +SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/local/i386-coff/lib);\n\ +ENTRY(_mainCRTStartup)\n\ +SECTIONS\n\ +{\n\ + .text 0x401000 : {\n\ + *(.text)\n\ + ;\n\ + }\n\ + .bss BLOCK(0x1000) :\n\ + { \n\ + *(.bss)\n\ + *(COMMON)\n\ + ;\n\ + }\n\ + .rdata BLOCK(0x1000) :\n\ + { \n\ + *(.rdata)\n\ + ;\n\ + }\n\ + .data BLOCK(0x1000) : {\n\ + *(.data)\n\ + *(.data2)\n\ + ;\n\ + }\n\ + .idata BLOCK(0x1000) :\n\ + { \n\ + *(.idata$2)\n\ + *(.idata$3)\n\ + *(.idata$4)\n\ + *(.idata$5)\n\ + *(.idata$6)\n\ + *(.idata$7)\n\ + ;\n\ + }\n\ + .CRT BLOCK(0x1000) :\n\ + { \n\ + *(.CRT$XCA)\n\ + *(.CRT$XCC)\n\ + *(.CRT$XCZ)\n\ + *(.CRT$XIA)\n\ + *(.CRT$XIC)\n\ + *(.CRT$XIZ)\n\ + *(.CRT$XLA)\n\ + *(.CRT$XLZ)\n\ + *(.CRT$XPA)\n\ + *(.CRT$XPX)\n\ + *(.CRT$XPZ)\n\ + *(.CRT$XTA)\n\ + *(.CRT$XTZ)\n\ + ;\n\ + }\n\ + .rsrc BLOCK(0x1000) :\n\ + { \n\ + *(.rsrc$01)\n\ + *(.rsrc$02)\n\ + ;\n\ + }\n\ + .reloc BLOCK(0x1000) :\n\ + { \n\ + *(.reloc)\n\ + ;\n\ + }\n\ + .junk BLOCK(0x1000) :\n\ + { \n\ + *(.debug$S)\n\ + *(.debug$T)\n\ + *(.debug$F)\n\ + *(.drectve)\n\ + ;\n\ + }\n\ +}\n\n" + ; +} + +struct ld_emulation_xfer_struct ld_i386pe_emulation = +{ + gldi386pe_before_parse, + syslib_default, + hll_default, + after_parse_default, + after_allocation_default, + set_output_arch_default, + ldemul_default_target, + before_allocation_default, + gldi386pe_get_script, + "i386pe", + "pe-i386" +}; +EOF
\ No newline at end of file diff --git a/ld/ldlang.c b/ld/ldlang.c index f7847d3..3c9350d 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -2752,6 +2752,21 @@ lang_section_start (name, address) called by ENTRY in a linker script. Command line arguments take precedence. */ +/* WINDOWS_NT. When an entry point has been specified, we will also force + this symbol to be defined by calling ldlang_add_undef (equivalent to + having switch -u entry_name on the command line). The reason we do + this is so that the user doesn't have to because they would have to use + the -u switch if they were specifying an entry point other than + _mainCRTStartup. Specifically, if creating a windows application, entry + point _WinMainCRTStartup must be specified. + What I have found for non console applications (entry not _mainCRTStartup) + is that the .obj that contains mainCRTStartup is brought in since it is + the first encountered in libc.lib and it has other symbols in it which will + be pulled in by the link process. To avoid this, adding -u with the entry + point name specified forces the correct .obj to be used. We can avoid + making the user do this by always adding the entry point name as an + undefined symbol. */ + void lang_add_entry (name, cmdline) CONST char *name; @@ -2766,6 +2781,14 @@ lang_add_entry (name, cmdline) entry_symbol = name; from_cmdline = cmdline; } +#ifdef 0 /* WINDOWS_NT */ + /* don't do this yet. It seems to work (the executables run), but the + image created is very different from what I was getting before indicating + that something else is being pulled in. When everything else is working, + then try to put this back in to see if it will do the right thing for + other more complicated applications */ + ldlang_add_undef (name); +#endif } void diff --git a/ld/scripttempl/.Sanitize b/ld/scripttempl/.Sanitize index bf8a171..46c2242 100644 --- a/ld/scripttempl/.Sanitize +++ b/ld/scripttempl/.Sanitize @@ -48,6 +48,7 @@ h8500m.sc h8500s.sc hppaelf.sc i386coff.sc +i386pe.sc i386go32.sc i386lynx.sc i960.sc diff --git a/ld/scripttempl/i386pe.sc b/ld/scripttempl/i386pe.sc new file mode 100644 index 0000000..d23506d --- /dev/null +++ b/ld/scripttempl/i386pe.sc @@ -0,0 +1,95 @@ +# Linker script for 386 PE. +# These are substituted in as variables in order to get '}' in a shell +# conditional expansion. +INIT='.init : { *(.init) }' +FINI='.fini : { *(.fini) }' +cat <<EOF +OUTPUT_FORMAT("${OUTPUT_FORMAT}") +${LIB_SEARCH_DIRS} + +ENTRY(_mainCRTStartup) + +SECTIONS +{ + + .text ${RELOCATING+ 0x401000} : + { + ${RELOCATING+ *(.init);} + *(.text) + ${RELOCATING+ *(.fini);} + ${RELOCATING+ etext = .}; + } + + .bss BLOCK(0x1000) : + { + *(.bss) + *(COMMON); + } + + .rdata BLOCK(0x1000) : + { + *(.rdata) + ; + } + .data BLOCK(0x1000) : { + *(.data) + *(.data2) + ; + } + .idata BLOCK(0x1000) : + { + *(.idata$2) + *(.idata$3) + *(.idata$4) + *(.idata$5) + *(.idata$6) + *(.idata$7) + ; + } + .CRT BLOCK(0x1000) : + { + *(.CRT$XCA) + *(.CRT$XCC) + *(.CRT$XCZ) + *(.CRT$XIA) + *(.CRT$XIC) + *(.CRT$XIZ) + *(.CRT$XLA) + *(.CRT$XLZ) + *(.CRT$XPA) + *(.CRT$XPX) + *(.CRT$XPZ) + *(.CRT$XTA) + *(.CRT$XTZ) + ; + } + .rsrc BLOCK(0x1000) : + { + *(.rsrc$01) + *(.rsrc$02) + ; + } + .reloc BLOCK(0x1000) : + { + *(.reloc) + ; + } + .junk BLOCK(0x1000) : + { + *(.debug$S) + *(.debug$T) + *(.debug$F) + *(.drectve) + ; + } + .stab 0 ${RELOCATING+(NOLOAD)} : + { + [ .stab ] + } + + .stabstr 0 ${RELOCATING+(NOLOAD)} : + { + [ .stabstr ] + } +} +EOF |