public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ld: revert default dll characteristics for Cygwin.
@ 2021-03-01 19:43 Jeremy Drake
  2021-03-13  6:16 ` ASSI
  2021-10-19 17:08 ` Corinna Vinschen
  0 siblings, 2 replies; 6+ messages in thread
From: Jeremy Drake @ 2021-03-01 19:43 UTC (permalink / raw)
  To: binutils

Mail thread from
https://cygwin.com/pipermail/cygwin/2021-February/247922.html suggests
these flags will NOT work for Cygwin, which relies on stable address
layouts for their fork() emulation.

In the process, renamed move_default_addr_high shell variable to
cygwin_beahior, as the old name wasn't quite accurate anymore and I
wanted to use it choose which dll characteristics flags to use by
default.

Also copied that switch to pe.em, as it was only in pep.em before but
32-bit also needed to switch defaults for Cygwin.
---
 ld/emultempl/pe.em  | 13 ++++++++++++-
 ld/emultempl/pep.em | 40 +++++++++++++++++++++-------------------
 2 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 748a6b49412..9f757cc31dc 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -5,6 +5,16 @@ if [ -z "$MACHINE" ]; then
 else
   OUTPUT_ARCH=${ARCH}:${MACHINE}
 fi
+
+case ${target} in
+  *-*-cygwin*)
+    cygwin_behavior=1
+    ;;
+  *)
+    cygwin_behavior=0;
+    ;;
+esac
+
 rm -f e${EMULATION_NAME}.c
 (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
 fragment <<EOF
@@ -104,7 +114,8 @@ fragment <<EOF
 #define DEFAULT_PSEUDO_RELOC_VERSION 1
 #endif

-#define DEFAULT_DLL_CHARACTERISTICS	(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
+#define DEFAULT_DLL_CHARACTERISTICS	(${cygwin_behavior} ? 0 : \
+					   IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
 					 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)

 #if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index ff49c15c002..69f5bd04655 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -8,10 +8,10 @@ fi

 case ${target} in
   *-*-cygwin*)
-    move_default_addr_high=1
+    cygwin_behavior=1
     ;;
   *)
-    move_default_addr_high=0;
+    cygwin_behavior=0;
     ;;
 esac

@@ -99,45 +99,47 @@ fragment <<EOF
 #define DLL_SUPPORT
 #endif

-#define DEFAULT_DLL_CHARACTERISTICS	(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
+#define DEFAULT_DLL_CHARACTERISTICS	(${cygwin_behavior} ? 0 : \
+					   IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
 					 | IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
 					 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)

+
 #if defined(TARGET_IS_i386pep) || ! defined(DLL_SUPPORT)
 #define	PE_DEF_SUBSYSTEM		3
 #undef NT_EXE_IMAGE_BASE
 #define NT_EXE_IMAGE_BASE \
-  ((bfd_vma) (${move_default_addr_high} ? 0x100400000LL \
-					: 0x140000000LL))
+  ((bfd_vma) (${cygwin_behavior} ? 0x100400000LL \
+				 : 0x140000000LL))
 #undef NT_DLL_IMAGE_BASE
 #define NT_DLL_IMAGE_BASE \
-  ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
-					: 0x180000000LL))
+  ((bfd_vma) (${cygwin_behavior} ? 0x400000000LL \
+				 : 0x180000000LL))
 #undef NT_DLL_AUTO_IMAGE_BASE
 #define NT_DLL_AUTO_IMAGE_BASE \
-  ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
-					: 0x1C0000000LL))
+  ((bfd_vma) (${cygwin_behavior} ? 0x400000000LL \
+				 : 0x1C0000000LL))
 #undef NT_DLL_AUTO_IMAGE_MASK
 #define NT_DLL_AUTO_IMAGE_MASK \
-  ((bfd_vma) (${move_default_addr_high} ? 0x1ffff0000LL \
-					: 0x1ffff0000LL))
+  ((bfd_vma) (${cygwin_behavior} ? 0x1ffff0000LL \
+				 : 0x1ffff0000LL))
 #else
 #undef  NT_EXE_IMAGE_BASE
 #define NT_EXE_IMAGE_BASE \
-  ((bfd_vma) (${move_default_addr_high} ? 0x100010000LL \
-					: 0x10000LL))
+  ((bfd_vma) (${cygwin_behavior} ? 0x100010000LL \
+				 : 0x10000LL))
 #undef NT_DLL_IMAGE_BASE
 #define NT_DLL_IMAGE_BASE \
-  ((bfd_vma) (${move_default_addr_high} ? 0x110000000LL \
-					: 0x10000000LL))
+  ((bfd_vma) (${cygwin_behavior} ? 0x110000000LL \
+				 : 0x10000000LL))
 #undef NT_DLL_AUTO_IMAGE_BASE
 #define NT_DLL_AUTO_IMAGE_BASE \
-  ((bfd_vma) (${move_default_addr_high} ? 0x120000000LL \
-					: 0x61300000LL))
+  ((bfd_vma) (${cygwin_behavior} ? 0x120000000LL \
+				 : 0x61300000LL))
 #undef NT_DLL_AUTO_IMAGE_MASK
 #define NT_DLL_AUTO_IMAGE_MASK \
-  ((bfd_vma) (${move_default_addr_high} ? 0x0ffff0000LL \
-					: 0x0ffc0000LL))
+  ((bfd_vma) (${cygwin_behavior} ? 0x0ffff0000LL \
+				 : 0x0ffc0000LL))
 #undef  PE_DEF_SECTION_ALIGNMENT
 #define	PE_DEF_SUBSYSTEM		2
 #undef  PE_DEF_FILE_ALIGNMENT
-- 
2.30.1.windows.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: revert default dll characteristics for Cygwin.
  2021-03-01 19:43 [PATCH] ld: revert default dll characteristics for Cygwin Jeremy Drake
@ 2021-03-13  6:16 ` ASSI
  2021-03-16 17:37   ` ASSI
  2021-10-19 17:08 ` Corinna Vinschen
  1 sibling, 1 reply; 6+ messages in thread
From: ASSI @ 2021-03-13  6:16 UTC (permalink / raw)
  To: binutils

Jeremy Drake via Binutils writes:
> Mail thread from
> https://cygwin.com/pipermail/cygwin/2021-February/247922.html suggests
> these flags will NOT work for Cygwin, which relies on stable address
> layouts for their fork() emulation.

I have not yet made up my mind about NX_COMPAT which may be useful to
have anyway (but just like ASLR is hard to get definitive documentation
on what it actually does on which version of Windows).

> In the process, renamed move_default_addr_high shell variable to
> cygwin_beahior, as the old name wasn't quite accurate anymore and I
> wanted to use it choose which dll characteristics flags to use by
> default.

I still think that just because it was Cygwin that uncovered that false
assumption there'd still be other toolchains which might need (or even
just want) to have different defaults.  So my request is still to a) have
proper configure options to set these defaults and b) not conflate them
into a single setting unless they really belong together.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: revert default dll characteristics for Cygwin.
  2021-03-13  6:16 ` ASSI
@ 2021-03-16 17:37   ` ASSI
  0 siblings, 0 replies; 6+ messages in thread
From: ASSI @ 2021-03-16 17:37 UTC (permalink / raw)
  To: binutils

ASSI writes:
> Jeremy Drake via Binutils writes:
>> Mail thread from
>> https://cygwin.com/pipermail/cygwin/2021-February/247922.html suggests
>> these flags will NOT work for Cygwin, which relies on stable address
>> layouts for their fork() emulation.
>
> I have not yet made up my mind about NX_COMPAT which may be useful to
> have anyway (but just like ASLR is hard to get definitive documentation
> on what it actually does on which version of Windows).

Another thing that does not sit well with me is that there quite likely
is a need to control the flags for exectutables and libraries
differently.  We already do that in Cygwin with the ts_aware flag (which
tacks onto executables only) in the toolchain configuration.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: revert default dll characteristics for Cygwin.
  2021-03-01 19:43 [PATCH] ld: revert default dll characteristics for Cygwin Jeremy Drake
  2021-03-13  6:16 ` ASSI
@ 2021-10-19 17:08 ` Corinna Vinschen
  2021-11-17 16:27   ` Nick Clifton
  1 sibling, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2021-10-19 17:08 UTC (permalink / raw)
  To: binutils

Any chance to get this patch into binutils soon?  

The default PE flag values generated for Cygwin executables are really a
problem in terms of dynamicbase.  We can change that on the compiler
command line, but that's just a workaround.


Thanks,
Corinna


On Mar  1 11:43, Jeremy Drake wrote:
> Mail thread from
> https://cygwin.com/pipermail/cygwin/2021-February/247922.html suggests
> these flags will NOT work for Cygwin, which relies on stable address
> layouts for their fork() emulation.
> 
> In the process, renamed move_default_addr_high shell variable to
> cygwin_beahior, as the old name wasn't quite accurate anymore and I
> wanted to use it choose which dll characteristics flags to use by
> default.
> 
> Also copied that switch to pe.em, as it was only in pep.em before but
> 32-bit also needed to switch defaults for Cygwin.
> ---
>  ld/emultempl/pe.em  | 13 ++++++++++++-
>  ld/emultempl/pep.em | 40 +++++++++++++++++++++-------------------
>  2 files changed, 33 insertions(+), 20 deletions(-)
> 
> diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
> index 748a6b49412..9f757cc31dc 100644
> --- a/ld/emultempl/pe.em
> +++ b/ld/emultempl/pe.em
> @@ -5,6 +5,16 @@ if [ -z "$MACHINE" ]; then
>  else
>    OUTPUT_ARCH=${ARCH}:${MACHINE}
>  fi
> +
> +case ${target} in
> +  *-*-cygwin*)
> +    cygwin_behavior=1
> +    ;;
> +  *)
> +    cygwin_behavior=0;
> +    ;;
> +esac
> +
>  rm -f e${EMULATION_NAME}.c
>  (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
>  fragment <<EOF
> @@ -104,7 +114,8 @@ fragment <<EOF
>  #define DEFAULT_PSEUDO_RELOC_VERSION 1
>  #endif
> 
> -#define DEFAULT_DLL_CHARACTERISTICS	(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
> +#define DEFAULT_DLL_CHARACTERISTICS	(${cygwin_behavior} ? 0 : \
> +					   IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
>  					 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
> 
>  #if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
> diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
> index ff49c15c002..69f5bd04655 100644
> --- a/ld/emultempl/pep.em
> +++ b/ld/emultempl/pep.em
> @@ -8,10 +8,10 @@ fi
> 
>  case ${target} in
>    *-*-cygwin*)
> -    move_default_addr_high=1
> +    cygwin_behavior=1
>      ;;
>    *)
> -    move_default_addr_high=0;
> +    cygwin_behavior=0;
>      ;;
>  esac
> 
> @@ -99,45 +99,47 @@ fragment <<EOF
>  #define DLL_SUPPORT
>  #endif
> 
> -#define DEFAULT_DLL_CHARACTERISTICS	(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
> +#define DEFAULT_DLL_CHARACTERISTICS	(${cygwin_behavior} ? 0 : \
> +					   IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
>  					 | IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
>  					 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
> 
> +
>  #if defined(TARGET_IS_i386pep) || ! defined(DLL_SUPPORT)
>  #define	PE_DEF_SUBSYSTEM		3
>  #undef NT_EXE_IMAGE_BASE
>  #define NT_EXE_IMAGE_BASE \
> -  ((bfd_vma) (${move_default_addr_high} ? 0x100400000LL \
> -					: 0x140000000LL))
> +  ((bfd_vma) (${cygwin_behavior} ? 0x100400000LL \
> +				 : 0x140000000LL))
>  #undef NT_DLL_IMAGE_BASE
>  #define NT_DLL_IMAGE_BASE \
> -  ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
> -					: 0x180000000LL))
> +  ((bfd_vma) (${cygwin_behavior} ? 0x400000000LL \
> +				 : 0x180000000LL))
>  #undef NT_DLL_AUTO_IMAGE_BASE
>  #define NT_DLL_AUTO_IMAGE_BASE \
> -  ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
> -					: 0x1C0000000LL))
> +  ((bfd_vma) (${cygwin_behavior} ? 0x400000000LL \
> +				 : 0x1C0000000LL))
>  #undef NT_DLL_AUTO_IMAGE_MASK
>  #define NT_DLL_AUTO_IMAGE_MASK \
> -  ((bfd_vma) (${move_default_addr_high} ? 0x1ffff0000LL \
> -					: 0x1ffff0000LL))
> +  ((bfd_vma) (${cygwin_behavior} ? 0x1ffff0000LL \
> +				 : 0x1ffff0000LL))
>  #else
>  #undef  NT_EXE_IMAGE_BASE
>  #define NT_EXE_IMAGE_BASE \
> -  ((bfd_vma) (${move_default_addr_high} ? 0x100010000LL \
> -					: 0x10000LL))
> +  ((bfd_vma) (${cygwin_behavior} ? 0x100010000LL \
> +				 : 0x10000LL))
>  #undef NT_DLL_IMAGE_BASE
>  #define NT_DLL_IMAGE_BASE \
> -  ((bfd_vma) (${move_default_addr_high} ? 0x110000000LL \
> -					: 0x10000000LL))
> +  ((bfd_vma) (${cygwin_behavior} ? 0x110000000LL \
> +				 : 0x10000000LL))
>  #undef NT_DLL_AUTO_IMAGE_BASE
>  #define NT_DLL_AUTO_IMAGE_BASE \
> -  ((bfd_vma) (${move_default_addr_high} ? 0x120000000LL \
> -					: 0x61300000LL))
> +  ((bfd_vma) (${cygwin_behavior} ? 0x120000000LL \
> +				 : 0x61300000LL))
>  #undef NT_DLL_AUTO_IMAGE_MASK
>  #define NT_DLL_AUTO_IMAGE_MASK \
> -  ((bfd_vma) (${move_default_addr_high} ? 0x0ffff0000LL \
> -					: 0x0ffc0000LL))
> +  ((bfd_vma) (${cygwin_behavior} ? 0x0ffff0000LL \
> +				 : 0x0ffc0000LL))
>  #undef  PE_DEF_SECTION_ALIGNMENT
>  #define	PE_DEF_SUBSYSTEM		2
>  #undef  PE_DEF_FILE_ALIGNMENT
> -- 
> 2.30.1.windows.1
> 
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: revert default dll characteristics for Cygwin.
  2021-10-19 17:08 ` Corinna Vinschen
@ 2021-11-17 16:27   ` Nick Clifton
  2021-11-17 16:36     ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Clifton @ 2021-11-17 16:27 UTC (permalink / raw)
  To: Corinna Vinschen, binutils

Hi Corinna,

> Any chance to get this patch into binutils soon?

If by soon you mean "almost a month later" then yes. :-(

> The default PE flag values generated for Cygwin executables are really a
> problem in terms of dynamicbase.  We can change that on the compiler
> command line, but that's just a workaround.

OK, it is done.  I simplified the patch to drop all the changes of
move_default_addr_high to cygwin_behaviour as it made the diff smaller,
but the essential element is there.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ld: revert default dll characteristics for Cygwin.
  2021-11-17 16:27   ` Nick Clifton
@ 2021-11-17 16:36     ` Corinna Vinschen
  0 siblings, 0 replies; 6+ messages in thread
From: Corinna Vinschen @ 2021-11-17 16:36 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

On Nov 17 16:27, Nick Clifton wrote:
> Hi Corinna,
> 
> > Any chance to get this patch into binutils soon?
> 
> If by soon you mean "almost a month later" then yes. :-(

Soon enough :)

> > The default PE flag values generated for Cygwin executables are really a
> > problem in terms of dynamicbase.  We can change that on the compiler
> > command line, but that's just a workaround.
> 
> OK, it is done.  I simplified the patch to drop all the changes of
> move_default_addr_high to cygwin_behaviour as it made the diff smaller,
> but the essential element is there.

Great, thanks a lot!


Corinna


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-17 16:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 19:43 [PATCH] ld: revert default dll characteristics for Cygwin Jeremy Drake
2021-03-13  6:16 ` ASSI
2021-03-16 17:37   ` ASSI
2021-10-19 17:08 ` Corinna Vinschen
2021-11-17 16:27   ` Nick Clifton
2021-11-17 16:36     ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).