From owner-freebsd-current@freebsd.org Wed Jun 10 16:59:16 2020 Return-Path: Delivered-To: freebsd-current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9D02B339C7C for ; Wed, 10 Jun 2020 16:59:16 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49htW827ttz4Ggl; Wed, 10 Jun 2020 16:59:16 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qt1-x82c.google.com with SMTP id y1so2282129qtv.12; Wed, 10 Jun 2020 09:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=JzZ/kV2lqfJbJBY7QySu2LY2il6V5gKxMblsPdAy5wM=; b=dVTIgWE1Rh35022+3LroApzp/PLZj0tx17xUmrUva2HEPsoM8Sso5J1bK2b8ZlNfD1 jTV1k8VLa9dutGryOTyDFU6WOXzY2PuT/RoeiOTRobq3Hp54eRmteZYmR4guInJ25fK2 bZtd7KxS94duwp2SRnqTWHQ7i9KIt82X735AnsmyCfiXAYLZLQWA3KhA3Jkx7kSGkIeW iM3dZoKafDL4CKLFVruAEoQWJbKltj1IBad+5n+t5ZgosGxA+Sb279uxrQcMadgH93Ig qMn4lAFlgcQNWUJeQ7FEMSD2E9iV7hJrs5qgjD9Lu/ZxrTh0jmAbkgYgWNRob15bSuUu svVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=JzZ/kV2lqfJbJBY7QySu2LY2il6V5gKxMblsPdAy5wM=; b=sd2Bq14DiYO6xg6mMIiNVg1l6Lkabsf5/787rBEMa3qDHn2YK2ORXLftjvhTucikZp Hpj948IolVT/EthE4vwm37mzfV956NvptZvCG+HOIhCqjOMc+ANTwGOxWt2Vgx0SsxtM /LmLZJEzCh+MqeNjFbl0IPmnRaf+jTo1t3HPpr2XB6cQjqFefTYjmeO7BvxvwMXlf/YR gTN6YastI5dWBJLVmYnpIapcBruaYa/wWf/qb5W27YVYN/sYgacnLMr9S+Pj0Gi21ZCp jpQvNvQSKNKOl0inw8JH1PzVgi9PN2yNa1DEYtgLXP8tM/JvSlh86cBSsm8bZqDB9wUM h31w== X-Gm-Message-State: AOAM530OX+L8SFxS47CESi+aZmMfolxmJ0Lks9StYfnHRSFLuCrs1nOk HMWTj0si/AewueUJcj5XWHOJ/uygCbY= X-Google-Smtp-Source: ABdhPJy60roR4tantMb/uLU2VtKQ110a4PAXxAY7wCpxcUx0OnrR/dnuwBX1rC6ftX1PlvL9/trBgQ== X-Received: by 2002:ac8:4c8d:: with SMTP id j13mr4371012qtv.38.1591808353873; Wed, 10 Jun 2020 09:59:13 -0700 (PDT) Received: from raichu (bras-base-toroon0560w-grc-21-184-147-207-195.dsl.bell.ca. [184.147.207.195]) by smtp.gmail.com with ESMTPSA id i33sm389095qtc.35.2020.06.10.09.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 09:59:13 -0700 (PDT) Sender: Mark Johnston Date: Wed, 10 Jun 2020 12:59:08 -0400 From: Mark Johnston To: Michael Tuexen Cc: "freebsd-current@FreeBSD.org" Subject: Re: gcc versus clang issue for 32-bit binaries Message-ID: <20200610165908.GA81346@raichu> References: <128AB51F-0950-448F-8463-12C573C1AA38@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <128AB51F-0950-448F-8463-12C573C1AA38@freebsd.org> X-Rspamd-Queue-Id: 49htW827ttz4Ggl X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jun 2020 16:59:16 -0000 On Wed, Jun 10, 2020 at 06:41:50PM +0200, Michael Tuexen wrote: > Dear all, > > consider the following program test.c: > > #include > #include > > int > main(void) > { > void *p; > > p = mmap((void *)0x20000000, 0x1000000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); > printf("p= %p\n", p); > return (0); > } > > On i386 the following happens: > * when compiling it with cc and running it, it crashes. > * when compiling it with gcc it runs fine. > > On amd64 the following happens: > * when compiling it with cc -m64 it runs fine. > * when compiling it with cc -m32 is crashes. > * when compiling it with gcc -m64 it runs fine. > * when compiling it with gcc -m32 it runs fine. > > So why does the above program crash when compiled for 32-bit when using clang, but runs fine when compiled with gcc. The difference is between ld.bfd and ld.lld, which emit executables with different entry point addresses. cc -m32 -fuse-ld=bfd gives an executable that does not crash. When linked with lld, libc and ld-elf get mapped into the region [0x20000000,0x21000000], so the program crashes when the libc.so mapping is overwritten with that created by the mmap() call and the program calls printf(). > I'm testing this on 32-bit and 64-bit head systems. gcc is from ports. > > The reason I'm looking into it is that I want to get syzkaller working on 32-bit with clang. Do you know why SYZ_DATA_OFFSET is hard-coded the way it is? It looks like it works more or less by accident, but at a glance I don't see why it has to be a fixed mapping.