From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10705 invoked by alias); 9 Mar 2009 01:13:58 -0000 Received: (qmail 10693 invoked by uid 22791); 9 Mar 2009 01:13:55 -0000 X-SWARE-Spam-Status: No, hits=2.2 required=5.0 tests=AWL,BAYES_20,J_CHICKENPOX_111,J_CHICKENPOX_15,J_CHICKENPOX_19,J_CHICKENPOX_210,J_CHICKENPOX_22,J_CHICKENPOX_24,J_CHICKENPOX_25,J_CHICKENPOX_26,J_CHICKENPOX_27,J_CHICKENPOX_28,J_CHICKENPOX_29,J_CHICKENPOX_32,SPF_PASS X-Spam-Check-By: sourceware.org Received: from nf-out-0910.google.com (HELO nf-out-0910.google.com) (64.233.182.191) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 09 Mar 2009 01:13:45 +0000 Received: by nf-out-0910.google.com with SMTP id f5so204462nfh.48 for ; Sun, 08 Mar 2009 18:13:41 -0700 (PDT) Received: by 10.210.29.11 with SMTP id c11mr3194915ebc.48.1236561221483; Sun, 08 Mar 2009 18:13:41 -0700 (PDT) Received: from ?82.6.108.62? (cpc2-cmbg8-0-0-cust61.cmbg.cable.ntl.com [82.6.108.62]) by mx.google.com with ESMTPS id k7sm6482002nfh.35.2009.03.08.18.13.39 (version=SSLv3 cipher=RC4-MD5); Sun, 08 Mar 2009 18:13:40 -0700 (PDT) Message-ID: <49B46F5B.9060005@gmail.com> Date: Mon, 09 Mar 2009 01:13:00 -0000 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Dave Korn CC: binutils@sourceware.org Subject: Re: [PATCH] New --pe-dll-characteristcs switch for PE ld. References: <49AFCC7F.3030304@gmail.com> <20090306054715.GA3388@ednor.casa.cgf.cx> <49B0C729.3010801@gmail.com> <20090306161319.GA6624@ednor.casa.cgf.cx> <49B1526C.2020809@gmail.com> In-Reply-To: <49B1526C.2020809@gmail.com> Content-Type: multipart/mixed; boundary="------------080201020201040808040906" X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2009-03/txt/msg00131.txt.bz2 This is a multi-part message in MIME format. --------------080201020201040808040906 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-length: 214 Dave Korn wrote: > Christopher Faylor wrote: >> or --pe-characteristics. Attached, generated by running "sed -e's/-dll-/-/g' over the last patch. Retested with same results as before. cheers, DaveK --------------080201020201040808040906 Content-Type: text/plain; name="pe-characteristics-patch.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pe-characteristics-patch.diff" Content-length: 28797 Index: include/coff/internal.h =================================================================== RCS file: /cvs/src/src/include/coff/internal.h,v retrieving revision 1.22 diff -p -u -r1.22 internal.h --- include/coff/internal.h 12 Jul 2007 07:16:41 -0000 1.22 +++ include/coff/internal.h 8 Mar 2009 04:01:20 -0000 @@ -185,7 +185,7 @@ struct internal_extra_pe_aouthdr 3 - WINDOWS_CUI runs in Windows char sub. (console app) 5 - OS2_CUI runs in OS/2 character subsystem 7 - POSIX_CUI runs in Posix character subsystem */ - short DllCharacteristics; /* flags for DLL init, use 0 */ + unsigned short DllCharacteristics; /* flags for DLL init, use 0 */ bfd_vma SizeOfStackReserve; /* amount of memory to reserve */ bfd_vma SizeOfStackCommit; /* amount of memory initially committed for initial thread's stack, default is 0x1000 */ Index: include/coff/pe.h =================================================================== RCS file: /cvs/src/src/include/coff/pe.h,v retrieving revision 1.18 diff -p -u -r1.18 pe.h --- include/coff/pe.h 4 Nov 2007 23:49:08 -0000 1.18 +++ include/coff/pe.h 8 Mar 2009 04:01:21 -0000 @@ -38,6 +38,17 @@ #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 +/* DllCharacteristics flag bits. The inconsistent naming may seem + odd, but that is how they are defined in the PE specification. */ +#define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040 +#define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080 +#define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100 +#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 +#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 +#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 +#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 +#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 + /* Additional flags to be set for section headers to allow the NT loader to read and write to the section data (to replace the addresses of data in dlls for one thing); also to execute the section in .text's case. */ Index: ld/NEWS =================================================================== RCS file: /cvs/src/src/ld/NEWS,v retrieving revision 1.100 diff -p -u -r1.100 NEWS --- ld/NEWS 3 Mar 2009 18:22:10 -0000 1.100 +++ ld/NEWS 8 Mar 2009 04:01:21 -0000 @@ -1,5 +1,9 @@ -*- text -*- +* A new command-line flag '--pe-characteristics' allows PE targets + to set the value of the PE file header's DllCharacteristics field, + using a flexible combination of numeric and symbolic names. + * New script function REGION_ALIAS to add alias names to memory regions. * PE targets no longer make use of the long section names PE extension to Index: ld/ld.texinfo =================================================================== RCS file: /cvs/src/src/ld/ld.texinfo,v retrieving revision 1.235 diff -p -u -r1.235 ld.texinfo --- ld/ld.texinfo 3 Mar 2009 18:22:10 -0000 1.235 +++ ld/ld.texinfo 8 Mar 2009 04:01:23 -0000 @@ -2257,6 +2257,57 @@ Sets the minor number of the ``os versio Sets the minor number of the ``subsystem version''. Defaults to 0. [This option is specific to the i386 PE targeted port of the linker] +@kindex --pe-characteristics +@item --pe-characteristics (@var{name}|@var{integer})@*@ @w{@ }@ @w{@ }@ @w{@ }@ @w{@ }[(',' | '|' | '+' | ':')(@var{name}|@var{integer})[...]] +Sets the value of the DllCharacteristics field in the PE header. The +value can be specified by using hexadecimal or decimal integers, or the +symbolic names of the various bits, optionally combined by any combination +of @samp{|}, @samp{+}, @samp{:} or @samp{,} characters. The following +short symbolic names are recognized, shown with the full name of the flag +(as given in the MS PE specification) to which they correspond, which is +also accepted: + +@table @samp +@item dynbase +@samp{IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE} + +@item forceinteg +@samp{IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY} + +@item nxcompat +@samp{IMAGE_DLL_CHARACTERISTICS_NX_COMPAT} + +@item noisolation +@samp{IMAGE_DLLCHARACTERISTICS_NO_ISOLATION} + +@item noseh +@samp{IMAGE_DLLCHARACTERISTICS_NO_SEH} + +@item nobind +@samp{IMAGE_DLLCHARACTERISTICS_NO_BIND} + +@item wdmdriver +@samp{IMAGE_DLLCHARACTERISTICS_WDM_DRIVER} + +@item tsaware +@samp{IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE} + +@end table +These options and separators can be combined with almost total +flexibility; for example, valid uses of this option include: + +@smallexample +--pe-characteristics=0x0400|0x0100 +@end smallexample +@smallexample +--pe-characteristics=1+128+1024,noseh,nobind +@end smallexample +@smallexample +--pe-characteristics noseh:nobind:tsaware +@end smallexample + +[This option is valid for all PE targeted ports of the linker] + @cindex DEF files, creating @cindex DLLs, creating @kindex --output-def Index: ld/emultempl/pe.em =================================================================== RCS file: /cvs/src/src/ld/emultempl/pe.em,v retrieving revision 1.146 diff -p -u -r1.146 pe.em --- ld/emultempl/pe.em 3 Mar 2009 18:22:11 -0000 1.146 +++ ld/emultempl/pe.em 8 Mar 2009 04:01:24 -0000 @@ -229,6 +229,8 @@ fragment <[<,|+:>[...]]\n\ + Sets PE header DllCharacteristics field.\n")); } +static const definfoflag * +find_pe_flag_name (char *name, const definfoflag *flagnames) +{ + int i; -static void -set_pe_name (char *name, long val) + /* Look for the name, return pointer to definfoflag if found. */ + if (flagnames) + for (i = 0; flagnames[i].name; i++) + if (strncmp (name, flagnames[i].name, flagnames[i].len) == 0) + return &flagnames[i]; + /* Unknown name could be an integer, so not an error here. */ + return 0; +} + +static definfo * +find_pe_name (char *name) { int i; - /* Find the name and set it. */ + /* Look for the name, return pointer to definfo. */ for (i = 0; init[i].ptr; i++) - { - if (strcmp (name, init[i].symbol) == 0) - { - init[i].value = val; - init[i].inited = 1; - if (strcmp (name,"__image_base__") == 0) - set_pe_name (U ("__ImageBase"), val); - return; - } - } + if (strcmp (name, init[i].symbol) == 0) + return &init[i]; + /* Unknown name is a serious internal coding error, so don't + bother to diagnose or return error indication, just bail. */ abort (); } +static void +set_pe_name (char *name, long val) +{ + /* Find the name and set it. */ + definfo *init = find_pe_name (name); + init->value = val; + init->inited = 1; + if (strcmp (name,"__image_base__") == 0) + set_pe_name (U ("__ImageBase"), val); +} static void set_pe_subsystem (void) @@ -543,6 +598,62 @@ set_pe_value (char *name) optarg = end; } +static char +is_flag_sep (char x) +{ + return x == '+' || x == '|' || x == ':' || x == ','; +} + +static void +set_pe_value_from_flags (char *name) +{ + long flags = 0; + definfo *init; + + /* Look up the symbolic flag names. Even if there aren't any we + will still parse multiple integers combined by separators. */ + init = find_pe_name (name); + + /* Parse the flags out of optarg. We accept any combination of + symbolic abbreviations and strtoul-parseable integers, separated + by any combination of '+', '|', ':' and ',' characters. */ + while (*optarg) + { + const definfoflag *flag; + + /* Deliberately allow multiple conjoined separators. */ + while (is_flag_sep (*optarg)) + optarg++; + + /* Even trailing at the end. */ + if (!*optarg) + break; + + flag = find_pe_flag_name (optarg, init->flagnames); + if (flag) + { + flags |= flag->value; + optarg += flag->len; + } + else + { + char *end; + long value; + value = strtoul (optarg, &end, 0); + if (end == optarg) + einfo (_("%P%F: unrecognised integer/flag '%s' for PE parameter '%s'\n"), + optarg, name); + flags |= value; + optarg = end; + } + /* If there's any more, we do insist on at least one separator. */ + if (*optarg && !is_flag_sep (*optarg)) + einfo (_("%P%F: unparseable at '%s' for PE parameter '%s'\n"), + optarg, name); + } + + set_pe_name (name, flags); +} static void set_pe_stack_heap (char *resname, char *comname) @@ -707,6 +818,9 @@ gld${EMULATION_NAME}_handle_option (int case OPTION_DISABLE_LONG_SECTION_NAMES: pe_use_coff_long_section_names = 0; break; + case OPTION_PE_DLL_CHARACTERISTICS: + set_pe_value_from_flags ("__dll_characteristics__"); + break; } return TRUE; } Index: ld/emultempl/pep.em =================================================================== RCS file: /cvs/src/src/ld/emultempl/pep.em,v retrieving revision 1.23 diff -p -u -r1.23 pep.em --- ld/emultempl/pep.em 3 Mar 2009 18:22:11 -0000 1.23 +++ ld/emultempl/pep.em 8 Mar 2009 04:01:24 -0000 @@ -179,7 +179,8 @@ enum options OPTION_EXCLUDE_MODULES_FOR_IMPLIB, OPTION_USE_NUL_PREFIXED_IMPORT_TABLES, OPTION_ENABLE_LONG_SECTION_NAMES, - OPTION_DISABLE_LONG_SECTION_NAMES + OPTION_DISABLE_LONG_SECTION_NAMES, + OPTION_PE_DLL_CHARACTERISTICS }; static void @@ -244,6 +245,7 @@ gld${EMULATION_NAME}_add_options #endif {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES}, {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES}, + {"pe-characteristics", required_argument, NULL, OPTION_PE_DLL_CHARACTERISTICS}, {NULL, no_argument, NULL, 0} }; @@ -256,14 +258,47 @@ gld${EMULATION_NAME}_add_options typedef struct { + const char *name; + int len; + int value; +} definfoflag; + +#define C(name) { #name, sizeof(#name) - 1, name } +#define CF(name,flag) { #name, sizeof(#name) - 1, flag } +static const definfoflag dllchrctnames[] = +{ + /* Accept a few handy abbreviations. */ + CF(dynbase, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE), + CF(forceinteg, IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY), + CF(nxcompat, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT), + CF(noisolation, IMAGE_DLLCHARACTERISTICS_NO_ISOLATION), + CF(noseh, IMAGE_DLLCHARACTERISTICS_NO_SEH), + CF(nobind, IMAGE_DLLCHARACTERISTICS_NO_BIND), + CF(wdmdriver, IMAGE_DLLCHARACTERISTICS_WDM_DRIVER), + CF(tsaware, IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE), + /* And the full names as defined in the PE specification. */ + C(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE), + C(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY), + C(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT), + C(IMAGE_DLLCHARACTERISTICS_NO_ISOLATION), + C(IMAGE_DLLCHARACTERISTICS_NO_SEH), + C(IMAGE_DLLCHARACTERISTICS_WDM_DRIVER), + C(IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE), + { 0, 0, 0 }, +}; + +typedef struct +{ void *ptr; int size; bfd_vma value; char *symbol; int inited; + const definfoflag *flagnames; } definfo; -#define D(field,symbol,def) {&pep.field,sizeof(pep.field), def, symbol,0} +#define D(field,symbol,def) {&pep.field,sizeof(pep.field), def, symbol, 0, 0} +#define DF(field,symbol,def,flags) {&pep.field,sizeof(pep.field), def, symbol, 0, flags} static definfo init[] = { @@ -271,7 +306,7 @@ static definfo init[] = #define IMAGEBASEOFF 0 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE), #define DLLOFF 1 - {&dll, sizeof(dll), 0, "__dll__", 0}, + {&dll, sizeof(dll), 0, "__dll__", 0, 0}, #define MSIMAGEBASEOFF 2 D(ImageBase,"___ImageBase", NT_EXE_IMAGE_BASE), D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT), @@ -288,7 +323,8 @@ static definfo init[] = D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000), D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000), D(LoaderFlags,"__loader_flags__", 0x0), - { NULL, 0, 0, NULL, 0 } + DF(DllCharacteristics, "__dll_characteristics__", 0x0, dllchrctnames), + { NULL, 0, 0, NULL, 0, 0 } }; @@ -346,30 +382,49 @@ gld_${EMULATION_NAME}_list_options (FILE executable image files\n")); fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\ in object files\n")); + fprintf (file, _(" --pe-characteristics [<,|+:>[...]]\n\ + Sets PE header DllCharacteristics field.\n")); #endif } +static const definfoflag * +find_pep_flag_name (char *name, const definfoflag *flagnames) +{ + int i; -static void -set_pep_name (char *name, bfd_vma val) + /* Look for the name, return pointer to definfoflag if found. */ + if (flagnames) + for (i = 0; flagnames[i].name; i++) + if (strncmp (name, flagnames[i].name, flagnames[i].len) == 0) + return &flagnames[i]; + /* Unknown name could be an integer, so not an error here. */ + return 0; +} + +static definfo * +find_pep_name (char *name) { int i; - /* Find the name and set it. */ + /* Look for the name, return pointer to definfo. */ for (i = 0; init[i].ptr; i++) - { - if (strcmp (name, init[i].symbol) == 0) - { - init[i].value = val; - init[i].inited = 1; - if (strcmp (name,"__image_base__") == 0) - set_pep_name ("___ImageBase", val); - return; - } - } + if (strcmp (name, init[i].symbol) == 0) + return &init[i]; + /* Unknown name is a serious internal coding error, so don't + bother to diagnose or return error indication, just bail. */ abort (); } +static void +set_pep_name (char *name, long val) +{ + /* Find the name and set it. */ + definfo *init = find_pep_name (name); + init->value = val; + init->inited = 1; + if (strcmp (name,"__image_base__") == 0) + set_pep_name ("___ImageBase", val); +} static void set_pep_subsystem (void) @@ -489,6 +544,62 @@ set_pep_value (char *name) optarg = end; } +static char +is_flag_sep (char x) +{ + return x == '+' || x == '|' || x == ':' || x == ','; +} + +static void +set_pep_value_from_flags (char *name) +{ + long flags = 0; + definfo *init; + + /* Look up the symbolic flag names. Even if there aren't any we + will still parse multiple integers combined by separators. */ + init = find_pep_name (name); + + /* Parse the flags out of optarg. We accept any combination of + symbolic abbreviations and strtoul-parseable integers, separated + by any combination of '+', '|', ':' and ',' characters. */ + while (*optarg) + { + const definfoflag *flag; + + /* Deliberately allow multiple conjoined separators. */ + while (is_flag_sep (*optarg)) + optarg++; + + /* Even trailing at the end. */ + if (!*optarg) + break; + + flag = find_pep_flag_name (optarg, init->flagnames); + if (flag) + { + flags |= flag->value; + optarg += flag->len; + } + else + { + char *end; + long value; + value = strtoul (optarg, &end, 0); + if (end == optarg) + einfo (_("%P%F: unrecognised integer/flag '%s' for PE parameter '%s'\n"), + optarg, name); + flags |= value; + optarg = end; + } + /* If there's any more, we do insist on at least one separator. */ + if (*optarg && !is_flag_sep (*optarg)) + einfo (_("%P%F: unparseable at '%s' for PE parameter '%s'\n"), + optarg, name); + } + + set_pep_name (name, flags); +} static void set_pep_stack_heap (char *resname, char *comname) @@ -647,6 +758,9 @@ gld${EMULATION_NAME}_handle_option (int case OPTION_DISABLE_LONG_SECTION_NAMES: pep_use_coff_long_section_names = 0; break; + case OPTION_PE_DLL_CHARACTERISTICS: + set_pep_value_from_flags ("__dll_characteristics__"); + break; } return TRUE; } Index: ld/testsuite/ld-pe/dllcharact-1.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-1.d diff -N ld/testsuite/ld-pe/dllcharact-1.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-1.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,7 @@ +#name: pe-characteristics-1 +#ld: --pe-characteristics=1+128+512:nxcompat\\|wdmdriver\\|forceinteg +#objdump: -p +#sed: -e '/^DllCharacteristics/!d' +#source: empty.s + +DllCharacteristics[ \t]*00002381 Index: ld/testsuite/ld-pe/dllcharact-2.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-2.d diff -N ld/testsuite/ld-pe/dllcharact-2.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-2.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,7 @@ +#name: pe-characteristics-2 +#ld: --pe-characteristics=0x1234 +#objdump: -p +#sed: -e '/^DllCharacteristics/!d' +#source: empty.s + +DllCharacteristics[ \t]*00001234 Index: ld/testsuite/ld-pe/dllcharact-3.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-3.d diff -N ld/testsuite/ld-pe/dllcharact-3.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-3.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,7 @@ +#name: pe-characteristics-3 +#ld: --pe-characteristics noseh:nobind:tsaware +#objdump: -p +#sed: -e '/^DllCharacteristics/!d' +#source: empty.s + +DllCharacteristics[ \t]*00008c00 Index: ld/testsuite/ld-pe/dllcharact-4.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-4.d diff -N ld/testsuite/ld-pe/dllcharact-4.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-4.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,7 @@ +#name: pe-characteristics-4 +#ld: --pe-characteristics=0x0400\\|0x0100 +#objdump: -p +#sed: -e '/^DllCharacteristics/!d' +#source: empty.s + +DllCharacteristics[ \t]*00000500 Index: ld/testsuite/ld-pe/dllcharact-5.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-5.d diff -N ld/testsuite/ld-pe/dllcharact-5.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-5.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,7 @@ +#name: pe-characteristics-5 +#ld: --pe-characteristics=1+128+1024,noseh,nobind +#objdump: -p +#sed: -e '/^DllCharacteristics/!d' +#source: empty.s + +DllCharacteristics[ \t]*00000c81 Index: ld/testsuite/ld-pe/dllcharact-fail-1.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-fail-1.d diff -N ld/testsuite/ld-pe/dllcharact-fail-1.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-fail-1.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,4 @@ +#name: pe-characteristics-fail-1 +#ld: --pe-characteristics=1+0xf00:+badname+ +#error: .*unrecognised integer/flag.* +#source: empty.s Index: ld/testsuite/ld-pe/dllcharact-fail-2.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-fail-2.d diff -N ld/testsuite/ld-pe/dllcharact-fail-2.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-fail-2.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,9 @@ +#name: pe-characteristics-fail-2 +#ld: --pe-characteristics=0xGoWrong:noseh +#error: .*(unrecognised integer/flag '0xGoWrong:noseh'|unparseable at 'xGoWrong:noseh').* +#source: empty.s + +## This one was interesting. Different libc strtoul implementations appear to +## behave differently: newlib regards '0x' as a hex prefix followed by an invalid +## hex number, GNU libc parses it as an integer zero followed by an 'x'. This +## could well be a bug in newlib. Index: ld/testsuite/ld-pe/dllcharact-fail-3.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-fail-3.d diff -N ld/testsuite/ld-pe/dllcharact-fail-3.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-fail-3.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,4 @@ +#name: pe-characteristics-fail-3 +#ld: --pe-characteristics 0x3DFG +#error: .*unparseable at.* +#source: empty.s Index: ld/testsuite/ld-pe/dllcharact-fail-4.d =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact-fail-4.d diff -N ld/testsuite/ld-pe/dllcharact-fail-4.d --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact-fail-4.d 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,4 @@ +#name: pe-characteristics-fail-4 +#ld: --pe-characteristics 1+noseh+0x3DFnobind +#error: .*unparseable at.* +#source: empty.s Index: ld/testsuite/ld-pe/dllcharact.exp =================================================================== RCS file: ld/testsuite/ld-pe/dllcharact.exp diff -N ld/testsuite/ld-pe/dllcharact.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/dllcharact.exp 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,43 @@ +# Expect script for --pe-characteristics command-line option tests. +# Copyright 2009 +# Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# 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 3 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., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +# This test can only be run on PE/COFF platforms. +if {![is_pecoff_format]} { + return +} + +# Now we repeatedly re-link it with different args, +# and check that the field gets set correctly. + +run_dump_test "dllcharact-1" +run_dump_test "dllcharact-2" +run_dump_test "dllcharact-3" +run_dump_test "dllcharact-4" +run_dump_test "dllcharact-5" + +run_dump_test "dllcharact-fail-1" +run_dump_test "dllcharact-fail-2" +run_dump_test "dllcharact-fail-3" +run_dump_test "dllcharact-fail-4" + + + Index: ld/testsuite/ld-pe/empty.s =================================================================== RCS file: ld/testsuite/ld-pe/empty.s diff -N ld/testsuite/ld-pe/empty.s --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ld/testsuite/ld-pe/empty.s 8 Mar 2009 04:01:26 -0000 @@ -0,0 +1,7 @@ + .text + .global _start + .global _mainCRTStartup +_start: +_mainCRTStartup: + .end + Index: ld/testsuite/lib/ld-lib.exp =================================================================== RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v retrieving revision 1.59 diff -p -u -r1.59 ld-lib.exp --- ld/testsuite/lib/ld-lib.exp 6 Feb 2009 16:56:12 -0000 1.59 +++ ld/testsuite/lib/ld-lib.exp 8 Mar 2009 04:01:26 -0000 @@ -582,11 +582,17 @@ proc simple_diff { file_1 file_2 } { # objdump: FLAGS # nm: FLAGS # objcopy: FLAGS +# readelf: FLAGS # Use the specified program to analyze the assembler or linker # output file, and pass it FLAGS, in addition to the output name. # Note that they are run with LC_ALL=C in the environment to give # consistent sorting of symbols. # +# sed: FLAGS +# Run SED with the specified flags on the analyzer output dump +# file to perform custom post-processing, before attempting to +# match it against the pattern lines. +# # source: SOURCE [FLAGS] # Assemble the file SOURCE.s using the flags in the "as" directive # and the (optional) FLAGS. If omitted, the source defaults to @@ -661,6 +667,7 @@ proc run_dump_test { name } { set opts(nm) {} set opts(objcopy) {} set opts(readelf) {} + set opts(sed) {} set opts(name) {} set opts(PROG) {} set opts(source) {} @@ -917,20 +924,31 @@ proc run_dump_test { name } { if { $progopts1 == "" } { set $progopts1 "-r" } verbose "running $binary $progopts $progopts1" 3 - # Objcopy, unlike the other two, won't send its output to stdout, - # so we have to run it specially. - set cmd "$binary $progopts $progopts1 $objfile > $dumpfile" - if { $program == "objcopy" } { - set cmd "$binary $progopts $progopts1 $objfile $dumpfile" + # Must be ready to post-process the dumpfile, if need be. Objcopy, + # unlike the other two, won't send its output to stdout, so we have + # to run it specially. + if { $opts(sed) != "" } { + set cmdoutput "| sed $opts(sed) > $dumpfile" + if { $program == "objcopy" } { + set cmdoutput "$dumpfile.1 && sed $opts(sed) < $dumpfile.1 > $dumpfile" + } + } else { + set cmdoutput "> $dumpfile" + if { $program == "objcopy" } { + set cmdoutput "$dumpfile" + } } + # Generate the main command line, minus redirects. + set cmd "$binary $progopts $progopts1 $objfile" + # Ensure consistent sorting of symbols if {[info exists env(LC_ALL)]} { set old_lc_all $env(LC_ALL) } set env(LC_ALL) "C" send_log "$cmd\n" - set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp"]] "" "/dev/null"] + set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp $cmdoutput"]] "" "/dev/null"] remote_upload host "ld.tmp" set comp_output [prune_warnings [file_contents "ld.tmp"]] remote_file host delete "ld.tmp" --------------080201020201040808040906--