NetBSD Problem Report #51030

From martin@duskware.de  Wed Mar 30 18:57:14 2016
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id DA73F7A46B
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 30 Mar 2016 18:57:14 +0000 (UTC)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: -pie -static does not work (test failure with MKPIE=yes builds)
X-Send-Pr-Version: 3.95

>Number:         51030
>Category:       toolchain
>Synopsis:       -pie -static does not work (test failure with MKPIE=yes builds)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 30 19:00:00 +0000 2016
>Closed-Date:    Sun Aug 18 05:37:37 +0000 2019
>Last-Modified:  Sun Aug 18 05:37:37 +0000 2019
>Originator:     Martin Husemann
>Release:        NetBSD 7.99.26
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD thirdstage.duskware.de 7.99.26 NetBSD 7.99.26 (MODULAR) #466: Tue Mar 29 13:18:26 CEST 2016 martin@thirdstage.duskware.de:/usr/src/sys/arch/sparc64/compile/MODULAR sparc64
Architecture: sparc64
Machine: sparc64
>Description:

In a build with MKPIE=yes set, the /usr/tests/lib/csu/ tests cause a
new failure (at least on sparc64). This is due to the
/usr/tests/lib/csu/h_initfini2 test being explicitly linked with
-static (this is what is tested) and MKPIE additionaly forcing -pie
LDFLAGS.

It is unclear what kind of binary the combination of "-pie -static"
should create.

On sparc64 currently a dynamic object with reference to the non-existent
dynamic linker /usr/lib/sparcv9/ld.so.1 is created and this binary is
not executable.

Adding -Wl,-dynamic-linker=/usr/libexec/ld.elf_so fixes the issue, but
then this is not a static binary any more.

>How-To-Repeat:

Compile hello word with:

cc -v -Wall -O2 -fPIE -pie -static hello.c

(assuming you have build your whole world with MKPIE=yes, otherwise it
will fail early) and try to run it. Verify file type with file(1)
and/or readelf -l.

>Fix:
Define proper semantics for "-pie -static" and fix whatever needs fixing
to get there. Jörg suggested a DYN object with interpreter pointing to
itself (how exactly?). Other options would be an empty path as interpreter.
None of these fit my definition of "static".

A completely different aproach would be an EXEC binary with load address NULL,
like this:

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 2 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000100000 0x0000000000000000 0x0000000000000000
                 0x0000000000136dd8 0x000000000013b810  RWE    100000
  NOTE           0x00000000002000b0 0x00000000001000b0 0x00000000001000b0
                 0x0000000000000048 0x0000000000000048  R      4

and assorted kernel fixes to treat this as PIE. This, at least, really is
a "static" binary.

>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: toolchain/51030: -pie -static does not work (test failure with MKPIE=yes builds)
Date: Thu, 31 Mar 2016 19:48:25 +0200

 OpenBSD uses a DYN object with no interpreter section - this makes sense,
 we should do the same.

 For now I'll make the test's makefile drop -pie for this binary.

 Martin 

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sun, 18 Aug 2019 05:37:37 +0000
State-Changed-Why:
That was the approach taken, eventually. Seems to work now. Please re-open if I'm wrong :-)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.