Package: binutils-mingw-w64
Version: 2.27.90.20161231-1+7.4
Severity: normal
Tags: patch

Dear Maintainer,

When building a Windows DLL and accompanying import library using
'i686-w64-mingw32-ld' or 'x86_64-w64-mingw32-ld', the import library
includes build timestamps as well as UID/GID, which makes it difficult
to build a reproducible package.

A simple test:

  export SOURCE_DATE_EPOCH=0
  echo 'int foo(){return 42;}' > foo.c
  i686-w64-mingw32-gcc -shared foo.c -o foo.dll -Wl,--out-implib=foo1.dll.a
  mv foo.dll foo1.dll
  sleep 1
  i686-w64-mingw32-gcc -shared foo.c -o foo.dll -Wl,--out-implib=foo2.dll.a
  mv foo.dll foo2.dll
  diff foo1.dll foo2.dll      # succeeds
  diff foo1.dll.a foo2.dll.a  # fails

>From what I can tell, it should be easy to fix this by setting the
BFD_DETERMINISTIC_OUTPUT flag when creating the import library:

--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -2736,6 +2736,7 @@
 
   bfd_set_format (outarch, bfd_archive);
   outarch->has_armap = 1;
+  outarch->flags |= BFD_DETERMINISTIC_OUTPUT;
 
   /* Work out a reasonable size of things to put onto one line.  */
   ar_head = make_head (outarch);


(I've tested this patch on stretch, using binutils-source 2.28-5,
binutils-mingw-w64 7.4, gcc-mingw-w64 6.3.0-14+19.3.)

I can't think of any reason that this should cause compatibility
issues, since (unlike "normal" ar archives) the import library that is
generated in this way doesn't correspond to any "real" object files.
Thus, I can't think of any reason not to enable deterministic mode
unconditionally in this case.

I do, however, note the comment in bsd_write_armap (bfd/archive.c):

  "Some linkers may require that the archive filesystem modification
  time is less than (or near to) the archive map timestamp.  Those
  linkers should not be used with deterministic mode.  (GNU ld and
  Gold do not have this restriction.)"

I don't know if this comment has any relevance to MinGW or any other
Windows compilers.  (It seems unlikely, since timestamps in Windows
filesystems have historically been such a mess to begin with.)


-- System Information:
Debian Release: 9.6
  APT prefers stable
  APT policy: (990, 'stable'), (500, 'stable-updates'), (500, 'stable-debug')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.9.0-8-amd64 (SMP w/40 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages binutils-mingw-w64 depends on:
ii  binutils-mingw-w64-i686    2.28-5+7.4+b4
ii  binutils-mingw-w64-x86-64  2.28-5+7.4+b4

binutils-mingw-w64 recommends no packages.

binutils-mingw-w64 suggests no packages.

-- debconf-show failed

Reply via email to