From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.6489.1681818753110587709 for ; Tue, 18 Apr 2023 04:52:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QMbQTD/M; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681818752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1U242mOs/BUB1jZMW4n9SF3ITkhv3zu4gp9c6ec2USc=; b=QMbQTD/McSPqwUR9Gl64w0iA5luZMFp47/JgO6QmO487+FseEHuRJYFfetgtLIaEbtDatH zl4MIrbTZEph74CJi19Iqunr6UFrXkzriiglgAmbQX3AoHBJhtFMEaeVgtCYXzrEWFddmE 6lSlllnqwVbxhfENLMA2mfy7jtpCSe4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-6MwJIRuIM6-8ORvbLBEmOg-1; Tue, 18 Apr 2023 07:52:26 -0400 X-MC-Unique: 6MwJIRuIM6-8ORvbLBEmOg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CB985855300; Tue, 18 Apr 2023 11:52:25 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03DC540C845F; Tue, 18 Apr 2023 11:52:23 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8DEC6180061C; Tue, 18 Apr 2023 13:52:21 +0200 (CEST) Date: Tue, 18 Apr 2023 13:52:21 +0200 From: "Gerd Hoffmann" To: devel@edk2.groups.io, ardb@kernel.org Cc: Marvin =?utf-8?Q?H=C3=A4user?= , Pawel Polawski , Dongyan Qian , Sunil V L , Baoqi Zhang , Chao Li , Rebecca Cran , Ard Biesheuvel , Zhiguang Liu , Liming Gao , Yuwei Chen , Leif Lindholm , Michael D Kinney , Daniel Schaefer , Bob Feng , Oliver Steffen Subject: Re: [edk2-devel] [PATCH v4 01/10] BaseTools: add BASETOOLS define Message-ID: References: <20230414080250.1357004-2-kraxel@redhat.com> <18EC1A6E-8B81-4564-83A5-DA8EC2BA54ED@posteo.de> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, > > Underlying problem is that x64 ProcessorBind.h sets visibility to > > hidden (anyone knows why?). > > Yes. Toolchains tend to assume that you are generating code for a > shared library once you enabled -fpic, and this results in lots of > pointless indirections via the GOT. (This has to do with the > copy-on-write footprint of shared library pages, as a GOT tends to > gather all relocated quantities in a small region of memory. It is > also related to ELF symbol preemption, which is another thing we don't > give a ^$& about). > > *However*, recent linkers do a better job getting rid of these GOT > references at link time, once you pass the --relax option. On X64 in > particular, there are special, relaxable GOTPCREL relocations now that > will not result in to symbol references via the GOT if the linker > notices that the symbol in question is never preempted and not > provided externally. > > So it is worth an experiment whether we still need this to begin with. Seems to work fine on fedora 37, even without adding --relax, maybe this is enabled by default (there is a --no-relax switch after all). I'll go try older distros / compilers / binutils too. What would be the failure mode? Errors on ELF -> PE conversion because a GOT is present? Or will things break at runtime? > > Seems to be fine for freestanding binaries, > > but when linking host tools against shared libraries things break. For > > some reason on ubuntu only, fedora works fine (both gcc and clang). > > > > Automatically detecting freestanding vs. hosted would be even better, > > anyone knows whenever there is a define which can be used for this? At > > least the gcc man page doesn't mention any ... > > ard@gambale:~/linux-build-x86$ gcc -dM -E -o - -xc - <<< ""|grep HOSTED > #define __STDC_HOSTED__ 1 > ard@gambale:~/linux-build-x86$ gcc -ffreestanding -dM -E -o - -xc - > <<< ""|grep HOSTED > #define __STDC_HOSTED__ 0 Nice. So we have a plan b in case just dropping it doesn't work out. take care, Gerd