Bug 81393 - Bootstrap failure on s390x-linux while building libgo against recent glibc
Summary: Bootstrap failure on s390x-linux while building libgo against recent glibc
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: go (show other bugs)
Version: 7.1.1
: P3 normal
Target Milestone: ---
Assignee: Andreas Krebbel
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-11 11:50 UTC by Jakub Jelinek
Modified: 2017-07-20 22:18 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-07-11 00:00:00


Attachments
Experimental patch (935 bytes, patch)
2017-07-11 16:19 UTC, Andreas Krebbel
Details | Diff
Tested Patch (930 bytes, patch)
2017-07-11 16:46 UTC, Andreas Krebbel
Details | Diff
Possible patch (466 bytes, patch)
2017-07-19 18:08 UTC, Ian Lance Taylor
Details | Diff
Possible patch (476 bytes, patch)
2017-07-19 20:38 UTC, Ian Lance Taylor
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2017-07-11 11:50:42 UTC
Current 7 branch doesn't build against recent glibc, not just because of libsanitizer issues tracked in another PR, but also due to:
../../../../libgo/go/syscall/syscall_linux_s390.go:16:16: error: reference to undefined name ‘PTRACE_GETREGS’
  return ptrace(PTRACE_GETREGS, pid, 0, uintptr(unsafe.Pointer(regsout)))
                ^
../../../../libgo/go/syscall/syscall_linux_s390.go:20:16: error: reference to undefined name ‘PTRACE_SETREGS’
  return ptrace(PTRACE_SETREGS, pid, 0, uintptr(unsafe.Pointer(regs)))
                ^
make[6]: *** [Makefile:3331: syscall.lo] Error 1

This is because glibc has removed those in:
https://sourceware.org/bugzilla/show_bug.cgi?id=21539
claiming the kernel never supported them and it never worked.

Thus, I think syscall_linux_s390{,x}.go should probably use PTRACE_GETREGSET and PTRACE_SETREGSET instead.

Elsewhere I found
static long
our_ptrace_getregs(pid_t pid, struct USER_REGS_TYPE *regs)
{
#ifdef AARCH64
    struct iovec iovec = { regs, sizeof(*regs) };
    return our_ptrace(PTRACE_GETREGSET, pid, (void *)NT_PRSTATUS, &iovec);
#else
    return our_ptrace(PTRACE_GETREGS, pid, NULL, regs);
#endif
}

static long
our_ptrace_setregs(pid_t pid, struct USER_REGS_TYPE *regs)
{
#ifdef AARCH64
    struct iovec iovec = { regs, sizeof(*regs) };
    return our_ptrace(PTRACE_SETREGSET, pid, (void *)NT_PRSTATUS, &iovec);
#else
    return our_ptrace(PTRACE_SETREGS, pid, NULL, regs);
#endif
}

where aarch64 doesn't support PTRACE_SETREGS/GETREGS similarly to s390{,x} (though for some reason doesn't provide any syscall_linux_{arm64,aarch64}.go or whatever).  In sysinfo.go I see PTRACE_{G,S}ETREGSET defined, but not NT_PRSTATUS (which is 1, in elf.h?), and I see _iovec type.
Comment 1 Andreas Krebbel 2017-07-11 16:19:30 UTC
Created attachment 41716 [details]
Experimental patch

The patch I'm currently testing
Comment 2 Andreas Krebbel 2017-07-11 16:46:47 UTC
Created attachment 41717 [details]
Tested Patch

I had to add typecasts also for the 64 bit code.
Comment 3 ian@gcc.gnu.org 2017-07-13 03:44:46 UTC
Author: ian
Date: Thu Jul 13 03:44:14 2017
New Revision: 250174

URL: https://gcc.gnu.org/viewcvs?rev=250174&root=gcc&view=rev
Log:
	PR go/81393
    syscall: don't use GETREGS/SETREGS on s390
    
    They were removed in recent glibc.
    
    Patch by Andreas Krebbel for GCC PR 81393.
    
    Reviewed-on: https://go-review.googlesource.com/48231

Modified:
    trunk/gcc/go/gofrontend/MERGE
    trunk/libgo/go/syscall/syscall_linux_s390.go
    trunk/libgo/go/syscall/syscall_linux_s390x.go
Comment 4 Ian Lance Taylor 2017-07-13 03:50:01 UTC
Should be fixed.
Comment 5 Jakub Jelinek 2017-07-17 17:27:45 UTC
Only on the trunk.  Could you please backport it to release branches as well?  I think all of gcc 7, 6 and 5 are affected by this.
Comment 6 Jakub Jelinek 2017-07-19 09:23:45 UTC
Note that the patch doesn't apply cleanly (capital vs. lowercase letter of some field), and depends on r249472, r249662 and r250324.
Comment 7 Jakub Jelinek 2017-07-19 12:35:28 UTC
Oh, and r249712.
Comment 8 Jakub Jelinek 2017-07-19 12:38:04 UTC
And r249663.  Perhaps it would be better for the release branches to just define the ptrace_area type in the *.go files like syscall_linux_alpha.go used to.
Comment 9 Ian Lance Taylor 2017-07-19 18:08:07 UTC
Created attachment 41791 [details]
Possible patch

I agree that the simplest approach is to not try to pick up the definitions from the header files for the older branches, but to just write them directly.  I don't have a way to test a patch; can you see if this one works?
Comment 10 Jakub Jelinek 2017-07-19 20:32:36 UTC
https://kojipkgs.fedoraproject.org//work/tasks/6506/20616506/build.log
That fails to build:
../../../../libgo/go/syscall/syscall_linux_s390.go:28:33: error: reference to undefined name 'regs'
   uint32(uintptr(unsafe.Pointer(regs))),
                                 ^
make[8]: Leaving directory '/builddir/build/BUILD/gcc-7.1.1-20170718/obj-s390x-redhat-linux/s390x-redhat-linux/32/libgo'
make[8]: *** [Makefile:3331: syscall.lo] Error 1
make[7]: *** [Makefile:2746: all-recursive] Error 1

Guess the each first
uint32(uintptr(unsafe.Pointer(regs)))
line should be actually
uint32(uintptr(unsafe.Pointer(regsout)))
Comment 11 Ian Lance Taylor 2017-07-19 20:38:49 UTC
Created attachment 41793 [details]
Possible patch

Sorry about that, updated patch.
Comment 12 Jakub Jelinek 2017-07-20 06:24:37 UTC
That is better, syscall_linux_s390.go already compiles, but syscall_linux_s390x.go still doesn't:
../../../libgo/go/syscall/syscall_linux_s390x.go:28:3: error: incompatible type for field 3 in struct construction (cannot use type uint32 as type uint64)
   uint32(uintptr(unsafe.Pointer(regs))),
   ^
../../../libgo/go/syscall/syscall_linux_s390x.go:37:3: error: incompatible type for field 3 in struct construction (cannot use type uint32 as type uint64)
   uint32(uintptr(unsafe.Pointer(regs))),
   ^
Those s390x two occurrences of uint32(uintptr(unsafe.Pointer(regs))) really should be uint64(uintptr(unsafe.Pointer(regs))).  Let me test that now.
Comment 13 Jakub Jelinek 2017-07-20 19:57:24 UTC
(In reply to Jakub Jelinek from comment #12)
> That is better, syscall_linux_s390.go already compiles, but
> syscall_linux_s390x.go still doesn't:
> ../../../libgo/go/syscall/syscall_linux_s390x.go:28:3: error: incompatible
> type for field 3 in struct construction (cannot use type uint32 as type
> uint64)
>    uint32(uintptr(unsafe.Pointer(regs))),
>    ^
> ../../../libgo/go/syscall/syscall_linux_s390x.go:37:3: error: incompatible
> type for field 3 in struct construction (cannot use type uint32 as type
> uint64)
>    uint32(uintptr(unsafe.Pointer(regs))),
>    ^
> Those s390x two occurrences of uint32(uintptr(unsafe.Pointer(regs))) really
> should be uint64(uintptr(unsafe.Pointer(regs))).  Let me test that now.

With that change it passed bootstrap/regtest on s390x-linux.
Comment 14 Ian Lance Taylor 2017-07-20 19:59:42 UTC
Thanks.  Do you want to commit or should I do it?
Comment 15 Jakub Jelinek 2017-07-20 20:10:25 UTC
You wrote it, so go ahead ;).
Comment 16 ian@gcc.gnu.org 2017-07-20 22:03:57 UTC
Author: ian
Date: Thu Jul 20 22:03:26 2017
New Revision: 250402

URL: https://gcc.gnu.org/viewcvs?rev=250402&root=gcc&view=rev
Log:
	PR go/81393
syscall: don't use GETREGS/SETREGS on s390

They were removed in recent glibc.

This is a backport of https://golang.org/cl/48231 to earlier branches.
Define required type and constants in syscall package directly, don't
try to pull them from the system header files.

Modified:
    branches/gcc-7-branch/libgo/go/syscall/syscall_linux_s390.go
    branches/gcc-7-branch/libgo/go/syscall/syscall_linux_s390x.go
Comment 17 ian@gcc.gnu.org 2017-07-20 22:04:20 UTC
Author: ian
Date: Thu Jul 20 22:03:48 2017
New Revision: 250403

URL: https://gcc.gnu.org/viewcvs?rev=250403&root=gcc&view=rev
Log:
	PR go/81393
syscall: don't use GETREGS/SETREGS on s390

They were removed in recent glibc.

This is a backport of https://golang.org/cl/48231 to earlier branches.
Define required type and constants in syscall package directly, don't
try to pull them from the system header files.

Modified:
    branches/gcc-6-branch/libgo/go/syscall/syscall_linux_s390.go
    branches/gcc-6-branch/libgo/go/syscall/syscall_linux_s390x.go
Comment 18 ian@gcc.gnu.org 2017-07-20 22:04:35 UTC
Author: ian
Date: Thu Jul 20 22:04:02 2017
New Revision: 250404

URL: https://gcc.gnu.org/viewcvs?rev=250404&root=gcc&view=rev
Log:
	PR go/81393
syscall: don't use GETREGS/SETREGS on s390

They were removed in recent glibc.

This is a backport of https://golang.org/cl/48231 to earlier branches.
Define required type and constants in syscall package directly, don't
try to pull them from the system header files.

Modified:
    branches/gcc-5-branch/libgo/go/syscall/syscall_linux_s390.go
    branches/gcc-5-branch/libgo/go/syscall/syscall_linux_s390x.go
Comment 19 Ian Lance Taylor 2017-07-20 22:18:53 UTC
Should be fixed everywhere, I hope.