X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=2.5 required=5.0 tests=AWL,BAYES_50,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 Message-ID: <49AC9BAB.9000700@gmail.com> Date: Tue, 03 Mar 2009 02:53:31 +0000 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: [1.7] rebaseall doesn't solve the problem References: <499F6682 DOT 1090204 AT cwilson DOT fastmail DOT fm> <20090224100616 DOT GC6035 AT calimero DOT vinschen DOT de> <49A85971 DOT 6070300 AT cwilson DOT fastmail DOT fm> <20090228104337 DOT GG19887 AT calimero DOT vinschen DOT de> <49A986B4 DOT 2080501 AT cwilson DOT fastmail DOT fm> <20090228195127 DOT GA26646 AT ednor DOT casa DOT cgf DOT cx> <20090228202850 DOT GB8503 AT calimero DOT vinschen DOT de> <20090302120756 DOT GA31166 AT calimero DOT vinschen DOT de> <49ABF7B5 DOT 5010605 AT cwilson DOT fastmail DOT fm> <49AC56FE DOT 4080708 AT gmail DOT com> <49AC90A5 DOT 2080001 AT cwilson DOT fastmail DOT fm> In-Reply-To: <49AC90A5.2080001@cwilson.fastmail.fm> Content-Type: multipart/mixed; boundary="------------060609060301080009030300" Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------060609060301080009030300 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Charles Wilson wrote: > Dave Korn wrote: >> Yep, this is exactly how I'm doing it. Patch will be posted shortly. >> Syntax looks like >> >> --pe-dll-characteristics=|[(+|,:)|[...]] >> >> e.g. >> >> --pe-dll-characteristics=0x0400|0x0100 >> --pe-dll-characteristics=1+128+1024,noseh,nobind >> --pe-dll-characteristics noseh:nobind:tsaware > > Nice. Where is the parsing done? I added a variant of pe.em#set_pe_name() that can understand those sorts of arguments, and a field in the definfo struct that allows to supply a list of the abbreviated names and their corresponding values, so the mechanism is nicely reusable. > Anyway, if you've implemented that option parsing using just a small bit > of magic over top of getopt_long, I'll just borrow it (both packages are > GPL) and try to keep the interfaces for > ld --pe-dll-characteristics > peflags --dll-characteristics > sorta similar Yep, that would obviously be A Good Thing (TM). > (with maybe some nice short synonyms for the common peflags actions). The mechanism is ready and waiting for you, just add the data tables! > OTOH, if it relies on a bunch of pre-existing ld/* glue, then... Nope, should be easy to cut out the relevant bits, discarding ld-isms, and paste the remainder into your code. Copy of WIP attached for your convenience; I've got to add doco and testcases before I can submit it, but the parsing stuff is ready to fly and I'd appreciate any extra testing it gets :) cheers, DaveK --------------060609060301080009030300 Content-Type: text/plain; name="pe-dll-characteristics-patch.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pe-dll-characteristics-patch.diff" ? x.s 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 3 Mar 2009 01:55:05 -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.97 diff -p -u -r1.97 NEWS --- ld/NEWS 18 Feb 2009 18:23:07 -0000 1.97 +++ ld/NEWS 3 Mar 2009 01:55:06 -0000 @@ -1,5 +1,9 @@ -*- text -*- +* A new command-line flag '--pe-dll-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. + * PE targets no longer make use of the long section names PE extension to the COFF format when generating executable images, by default. The old (slightly non-conformant) behaviour can still be invoked by using the Index: ld/emultempl/pe.em =================================================================== RCS file: /cvs/src/src/ld/emultempl/pe.em,v retrieving revision 1.145 diff -p -u -r1.145 pe.em --- ld/emultempl/pe.em 27 Feb 2009 19:01:56 -0000 1.145 +++ ld/emultempl/pe.em 3 Mar 2009 01:55:06 -0000 @@ -229,6 +229,8 @@ fragment <.dll\n\ + an importlib, use .dll\n\ + an importlib, use .dll\n\ + an importlib, use .dll\n")); } +static const definfoflag * +find_pe_flag_name (char *name, const definfoflag *flagnames) +{ + int i; + + /* Look for the name, return pointer to definfoflag if found. */ + 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 void -set_pe_name (char *name, long val) +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 +600,58 @@ 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++; + + 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 +816,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.22 diff -p -u -r1.22 pep.em --- ld/emultempl/pep.em 18 Feb 2009 18:23:07 -0000 1.22 +++ ld/emultempl/pep.em 3 Mar 2009 01:55:06 -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-dll-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 } + D(DllCharacteristics, "__dll_characteristics__", 0x0), + { NULL, 0, 0, NULL, 0, 0 } }; @@ -346,30 +382,51 @@ 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-dll-characteristics mes Never use long COFF section names, even\n\ + an importlib, use .dll\n\ + an importlib, use .dll\n\ + an importlib, use .dll\n\ + an importlib, use .dll\n")); #endif } +static const definfoflag * +find_pep_flag_name (char *name, const definfoflag *flagnames) +{ + int i; + + /* Look for the name, return pointer to definfoflag if found. */ + 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 void -set_pep_name (char *name, bfd_vma val) +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 +546,58 @@ 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++; + + 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 +756,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; } --------------060609060301080009030300 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --------------060609060301080009030300--