Subject: Re: bug#18896: regressions in coreutils 8.23 on Yosemite

From: Jack Howarth <[email-masked]>
Date: Mon, 3 Nov 2014 16:58:59 -0500

On Mon, Nov 03, 2014 at 03:16:58PM +0100, Pádraig Brady wrote:
> On 10/31/2014 05:03 PM, Pádraig Brady wrote:
> > On 10/31/2014 03:41 PM, Jack Howarth wrote:
> >> On Fri, Oct 31, 2014 at 03:56:06AM +0000, Pádraig Brady wrote:
> >>> On 10/31/2014 03:30 AM, Jack Howarth wrote:
> >>>> On Fri, Oct 31, 2014 at 02:29:05AM +0000, Pádraig Brady wrote:
> >>>>>
> >>>>> So linkat() is now available but doesn't support hardlinks to symlinks
> >>>>> contrary to the POSIX spec. So it would be best we consider linkat()
> >>>>> unavailable, which can be done manually like:
> >>>>>
> >>>>>   ac_cv_func_linkat=no ./configure
> >>>>>
> >>>>> We'll have to augment the gnulib linkat check to actually check
> >>>>> that linkat() works, rather than just being available.
> >>>>
> >>>> Passing ac_cv_func_linkat=no to configure and using your attached patch
> >>>> results in a large number of failures on x86_64-apple-darwin14.
> >>>
> >>> Good that's better. coreutils tests have passed, and you're getting
> >>> to gnulib issues below.
> 
> I pushed the following slightly different more general patch
> to gnulib to address this issue:
> http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=c8e57ce5
> 
> thanks,
> Pádraig.

Pádraig,
     I puzzled out the problem with the strtoll test compilation. I have 
been using...

./configure CPPFLAGS="-Wall -std=c89"

but it appears it needs to be...

./configure CPPFLAGS="-Wall -std=c99"

on darwin14. The current gnulib git at your commit and the changes...

diff --git a/lib/symlinkat.c b/lib/symlinkat.c
index 9797f46..5df605f 100644
--- a/lib/symlinkat.c
+++ b/lib/symlinkat.c
@@ -20,6 +20,8 @@
 
 #include <unistd.h>
 #include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
 
 #if HAVE_SYMLINKAT
 # undef symlinkat
diff --git a/tests/test-stdnoreturn.c b/tests/test-stdnoreturn.c
index a8aead8..04107bc 100644
--- a/tests/test-stdnoreturn.c
+++ b/tests/test-stdnoreturn.c
@@ -18,6 +18,8 @@
 
 #include <config.h>
 
+#include <unistd.h>
+
 #include <stdnoreturn.h>
 
 #include <stdlib.h>

passes 'make' but the 'make check' produces 9 failures...

../build-aux/test-driver: line 107:  3918 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-getlogin_r
../build-aux/test-driver: line 107:  3925 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-getopt
../build-aux/test-driver: line 107:  4246 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-linkat
../build-aux/test-driver: line 107:  5143 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-readlinkat
../build-aux/test-driver: line 107:  5498 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-snprintf-posix
../build-aux/test-driver: line 107:  5522 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-sprintf-posix
../build-aux/test-driver: line 107:  6031 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-unlinkat
../build-aux/test-driver: line 107:  6225 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-vsnprintf-posix
../build-aux/test-driver: line 107:  6238 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test-vsprintf-posix

which debug as...

$ sudo lldb ./test-linkat
Password:
(lldb) target create "./test-linkat"
Current executable set to './test-linkat' (x86_64).
(lldb) r
Process 6515 launched: './test-linkat' (x86_64)
./test-link.h:166: assertion 'func (BASE "b", BASE "link/") == -1' failed
Process 6515 stopped
* thread #1: tid = 0xe205e7, 0x00007fff962cd282 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff962cd282 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill + 10:
-> 0x7fff962cd282:  jae    0x7fff962cd28c            ; __pthread_kill + 20
   0x7fff962cd284:  movq   %rax, %rdi
   0x7fff962cd287:  jmp    0x7fff962c8ca3            ; cerror_nocancel
   0x7fff962cd28c:  retq   
(lldb) bt
* thread #1: tid = 0xe205e7, 0x00007fff962cd282 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff962cd282 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff8ffc44c3 libsystem_pthread.dylib`pthread_kill + 90
    frame #2: 0x00007fff8bfe7b73 libsystem_c.dylib`abort + 129
    frame #3: 0x0000000100004426 test-linkat`test_link(func=<unavailable>, print=<unavailable>) + 4534 at test-link.h:32
    frame #4: 0x00000001000009fd test-linkat`main + 365 at test-linkat.c:124
    frame #5: 0x00007fff999935c9 libdyld.dylib`start + 1
(lldb) 

static int
test_link (int (*func) (char const *, char const *), bool print)
{
  int fd;
  int ret;

  /* Create first file.  */
  fd = open (BASE "a", O_CREAT | O_EXCL | O_WRONLY, 0600);
  ASSERT (0 <= fd);                                                <=== crash
  ASSERT (write (fd, "hello", 5) == 5);
  ASSERT (close (fd) == 0);

and

$ sudo lldb ./test-readlinkat
(lldb) target create "./test-readlinkat"
Current executable set to './test-readlinkat' (x86_64).
(lldb) r
Process 6538 launched: './test-readlinkat' (x86_64)
./test-readlink.h:71: assertion 'func (BASE "link2/", buf, sizeof buf) == -1' failed
Process 6538 stopped
* thread #1: tid = 0xe209a8, 0x00007fff962cd282 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff962cd282 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill + 10:
-> 0x7fff962cd282:  jae    0x7fff962cd28c            ; __pthread_kill + 20
   0x7fff962cd284:  movq   %rax, %rdi
   0x7fff962cd287:  jmp    0x7fff962c8ca3            ; cerror_nocancel
   0x7fff962cd28c:  retq   
(lldb) bt
* thread #1: tid = 0xe209a8, 0x00007fff962cd282 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff962cd282 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff8ffc44c3 libsystem_pthread.dylib`pthread_kill + 90
    frame #2: 0x00007fff8bfe7b73 libsystem_c.dylib`abort + 129
    frame #3: 0x0000000100001b9b test-readlinkat`test_readlink(print=<unavailable>, func=<unavailable>) + 3083 at test-readlink.h:34
    frame #4: 0x00000001000008de test-readlinkat`main + 174 at test-readlinkat.c:76
    frame #5: 0x00007fff999935c9 libdyld.dylib`start + 1
(lldb) 

which is at...

static int
test_readlink (ssize_t (*func) (char const *, char *, size_t), bool print)
{
  char buf[80];

  /* Sanity checks of failures.  Mingw lacks symlink, but readlink can
     still distinguish between various errors.  */
  memset (buf, 0xff, sizeof buf);
  errno = 0;
  ASSERT (func ("no_such", buf, sizeof buf) == -1);  <<<<<< crash
  ASSERT (errno == ENOENT);

Oddly some tests still pass in the debugger...

$ sudo lldb ./test-unlinkat
(lldb) target create "./test-unlinkat"
Current executable set to './test-unlinkat' (x86_64).
(lldb) r
Process 6533 launched: './test-unlinkat' (x86_64)
Process 6533 exited with status = 0 (0x00000000) 
(lldb) 

which in my experience often happens when there is an invalid memory access being suppressed in eh.
             Jack