Bug 225946 - /usr/bin/make dumps core with simple Makefile
Summary: /usr/bin/make dumps core with simple Makefile
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: Simon J. Gerraty
URL:
Keywords: toolchain
Depends on:
Blocks:
 
Reported: 2018-02-16 07:27 UTC by itsdavidmarx
Modified: 2018-09-22 10:06 UTC (History)
5 users (show)

See Also:
koobs: mfc-stable11+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description itsdavidmarx 2018-02-16 07:27:12 UTC
/usr/bin/make core dumps with this Makefile for an archive.
Actually the goal is to have the Makefile work without the
foo.o: foo.c entry, as it does with gmake, but for some reason
I think /usr/bin/make realizes it needs to make lib.a(foo.o) 
but doesn't make it.
For:
% uname -a
FreeBSD metro-6.us.oracle.com 12.0-CURRENT FreeBSD 12.0-CURRENT #10 d26791952(trueos-stable-17.12): Sat Dec  9 18:10:09 UTC 2017     root@chimera:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64
% cat foo.c
void
foo (
  void)
{
        }
% cat Makefile
all: lib.a

lib.a: lib.a(foo.o)
        ranlib lib.a

.c.a:
        cc -c foo.c
        ar rv lib.a foo.o
        rm -f foo.o

foo.o: foo.c
        cc -c foo.c

clobber: clean
        rm lib.a

clean:
        rm -f foo.o
% /usr/bin/make
Segmentation fault
% gdb /usr/bin/make
run
% gdb /usr/bin/make
GNU gdb (GDB) 8.0.1 [GDB v8.0.1 for FreeBSD]
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-portbld-freebsd12.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/make...Reading symbols from /usr/lib/debug//usr/bin/make.debug...done.
done.
(gdb) run
Starting program: /usr/bin/make

Program received signal SIGSEGV, Segmentation fault.
strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:102
102     /usr/src/lib/libc/string/strlen.c: No such file or directory.
(gdb) where
#0  strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:102
#1  0x000000000041aba2 in Var_Set (name=<optimized out>, val=<optimized out>,
    ctxt=0x800cf6ac0, flags=0) at /usr/src/contrib/bmake/var.c:973
#2  0x0000000000402090 in Compat_Make (gnp=0x800cf6b80, pgnp=0x800cf6ac0)
    at /usr/src/contrib/bmake/compat.c:657
#3  0x000000000041faf6 in Lst_ForEachFrom (l=0x800d700a0, ln=0x800d3e1c0,
    proc=0x401fd0 <Compat_Make>, d=0x800cf6ac0)
    at /usr/src/contrib/bmake/lst.lib/lstForEachFrom.c:104
#4  0x0000000000402041 in Compat_Make (gnp=0x800cf6ac0, pgnp=0x800cf6940)
    at /usr/src/contrib/bmake/compat.c:544
#5  0x000000000041faf6 in Lst_ForEachFrom (l=0x800d6fdd0, ln=0x800d3e160,
    proc=0x401fd0 <Compat_Make>, d=0x800cf6940)
    at /usr/src/contrib/bmake/lst.lib/lstForEachFrom.c:104
#6  0x0000000000402041 in Compat_Make (gnp=0x800cf6940, pgnp=0x800cf6880)
    at /usr/src/contrib/bmake/compat.c:544
#7  0x000000000041faf6 in Lst_ForEachFrom (l=0x800d6fc20, ln=0x800d71900,
    proc=0x401fd0 <Compat_Make>, d=0x800cf6880)
    at /usr/src/contrib/bmake/lst.lib/lstForEachFrom.c:104
#8  0x0000000000402041 in Compat_Make (gnp=0x800cf6880, pgnp=0x800cf67c0)
    at /usr/src/contrib/bmake/compat.c:544
#9  0x000000000041faf6 in Lst_ForEachFrom (l=0x800d6fb00, ln=0x800d718a0,
    proc=0x401fd0 <Compat_Make>, d=0x800cf67c0)
    at /usr/src/contrib/bmake/lst.lib/lstForEachFrom.c:104
---Type <return> to continue, or q <return> to quit---
#10 0x0000000000402041 in Compat_Make (gnp=0x800cf67c0, pgnp=0x800cf67c0)
    at /usr/src/contrib/bmake/compat.c:544
#11 0x00000000004024e6 in Compat_Run (targs=0x800cfa3a0)
    at /usr/src/contrib/bmake/compat.c:761
#12 0x000000000040cce7 in runTargets () at /usr/src/contrib/bmake/main.c:960
#13 main (argc=1, argv=<optimized out>) at /usr/src/contrib/bmake/main.c:1498
(gdb) x/i $rip
=> 0x460b7f <strlen+31>:        mov    (%rcx),%rax
(gdb) x/x $rcx
0x0:    Cannot access memory at address 0x0
(gdb)
Appears to be strlen of a null pointer.
Whatever garbage I give make, it should not core dump.
And this does work with gmake.

Thanks.
Comment 1 Bob Bishop 2018-02-16 11:22:59 UTC
Also affects 11.1-RELEASE-p4
Comment 2 Yuri Pankov 2018-09-09 08:27:09 UTC
This seems to be fixed in base r330260:

commit 490c4b4d3b3e2a78d91d2e02d19e3f2d5e639d1f
Merge: e80e5ef0ef6c bfa30a317c88
Author: sjg <sjg@FreeBSD.org>
Date:   Fri Mar 2 01:53:50 2018 +0000

    Update to bmake-201802222

    Fixes segfault in Var_Set if val is NULL
    Don't treat .info as warning with -W

Notes:
    svn path=/head/; revision=330260
Comment 3 Kubilay Kocak freebsd_committer freebsd_triage 2018-09-22 10:06:08 UTC
MFC'd to stable/11 by sjg in base r331246 as part of bug 226678

Assign to committer that resolved