From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id B108D3857415 for ; Wed, 25 Aug 2021 17:52:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B108D3857415 Received: by mail-pj1-x1029.google.com with SMTP id mw10-20020a17090b4d0a00b0017b59213831so4712553pjb.0 for ; Wed, 25 Aug 2021 10:52:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=R2QqB2TBiuAQK1vaS0oyCiGw8Z6s7u2k9I/GEPBPtpQ=; b=BB8cYH0mVJKNcymw+M8jpnlleEJQf23sozdBT50D81/SOyAeSoJgIax6CuFxf66AA0 k1Z2KmlBEylw2YCuX6JmCMBcsAxdPUiS/ijqRkLBN1alLH+NY+KxdbzW3eupDUr+efDK lJYYuCuOHyNR557CwAg/aKo5rndY835ndl3cT9xFaDsbda28scu74RaEdbudzXEVWKV4 lRAv5jsKZpeOQAr6aDjczLGybhfN3S1q4tTQJcg9zk5R/pgLCLSywmLu2qDo0PIRJJlz ZPxjSFVNEqTEZv5ynVU8zmYVmUeFcwmnh2tY9G4eWGUyUnyKI9lV8RQjpghyjOx/IQew 95DQ== X-Gm-Message-State: AOAM531ZEpQi2gG3gv/n9JhhVtYjRznLE5mEB5X0LabPr03IQdSkHWOZ G2sPgwKHo8ZDEbP0n8NHp1FCZVGHxPbmDp5jMPo= X-Google-Smtp-Source: ABdhPJwqA/wd0NtjZeNs4w2cAfCQ2ayr3Nh4loA0YnMQigmfyXSXVHJLzRkIDw0zPsd5ydd0vBdl/jMCM0XTRPYe3Lo= X-Received: by 2002:a17:90a:2a88:: with SMTP id j8mr11916058pjd.153.1629913942660; Wed, 25 Aug 2021 10:52:22 -0700 (PDT) MIME-Version: 1.0 References: <7F4EA5FF-0CDC-4C0C-BF2B-B276C1A4E434@sandoe.co.uk> <7E483B90-25B7-494C-9BC5-2BC51D2BEB78@sandoe.co.uk> <85254E55-ED0C-4CB8-82E0-B9B2E5EF2E0D@googlemail.com> In-Reply-To: <85254E55-ED0C-4CB8-82E0-B9B2E5EF2E0D@googlemail.com> From: "H.J. Lu" Date: Wed, 25 Aug 2021 10:51:46 -0700 Message-ID: Subject: Re: [PATCH] configure: Allow a host makefile fragment to override PIE flag settings. To: Iain Sandoe Cc: GCC Patches , Richard Sandiford Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3024.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Aug 2021 17:52:34 -0000 On Wed, Aug 25, 2021 at 10:42 AM Iain Sandoe wrot= e: > > Hi, > > > On 20 Aug 2021, at 11:29, Richard Sandiford = wrote: > > > >>> Maybe it would be easier to have the makefile fragments determine > >>> something like CODE_MODEL_CFLAGS, which can be "-fPIC", "-mdynamic-no= -pic", > >>> etc., and use: > >>> > >>> COMPILER +=3D $(NO_PIE_CFLAGS) $(CODE_MODEL_CFLAGS) > >> > >> OK. I have misgivings about this - the problem is that: > >> > >> -fPIC -fno-PIE !=3D -fno-PIE -fPIC, which is not obvious to many folk= s - who expect that > >> the =E2=80=9Clast edition of a flag will be the one in force=E2=80=9D. > >> > >> So the PIE-ness and the PIC-ness are decoupled in the configury but th= ey need to be > >> ordered specifically for targets that want PIC code by default (FWIW, = I don=E2=80=99t think Darwin > >> is the only default-PIC case here, from discussions on irc). > > > > Yeah, that's what the above was supposed to achieve. In other words, > > if you force non-PIE, you also need to follow that by $(CODE_MODEL_CFLA= GS), > > which restates whatever the base code model is. > > > > If it's the decoupling you're worried about, then an alternative would > > be to have: > > > > NO_PIE_CFLAGS=3D"-fno-PIE \$(CODE_MODEL_CFLAGS)=E2=80=9D > > I=E2=80=99d like to ask a couple of questions (of HJ who introduced the n= o-PIE logic) before implementing this. > > A. We use no-PIE for cc1* because that is needed to handle the PCH implem= entation (which relies on the executables being loaded at the same addresse= s each time). > > B. It=E2=80=99s certainly not obvious to me why we need to build code to = run on $build to be no-PIE - I don=E2=80=99t see any such dependencies in t= he generators etc. > > - So Question1 - HJ what was the motivation for making the XXX_BUILD_XX= X adopt no-PIE? https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D71934 > =E2=80=94=E2=80=94 > > Independently of this we seem to be building the objects for $host thus: > > $(CXX) (NO_PIE_CFLAGS) -c $(ALL_CXXFLAGS) etc. > > but we build for $build thus: > > $(CXX) -c $(ALL_CXXFLAGS) $(GENERATOR_CFLAGS) -DGENERATOR_FILE $(BUILD_NO= _PIE_CFLAGS) $(BUILD_CPPFLAGS) > > which means that code model flags in $ALL_CXXFLAGS are overridden for $bu= ild, but active for $host > ^^ this is actually what causes the Darwin build fail - since on Darwin w= e cannot build static linked code for user-space processes. > > in any event that=E2=80=99s inconsistent (unless there=E2=80=99s a reason= that it should be different). > > ---- > > below are extracts from gcc/Makefile *on linux* which demonstrates the di= fferent ordering. > > AFAICT, > NO_PIE_CFLAGS_FOR_BUILD, NO_PIE_FLAG_FOR_BUILD are dead variables? > > Question 2 : HJ, what was your intention for how a configuration would re= quest PIC code (for example) for things to run on $build? > > thanks > Iain > > ------- > > > ALL_CXXFLAGS =3D $(T_CFLAGS) $(CFLAGS-$@) $(CXXFLAGS) $(INTERNAL_CFLAGS) = \ > $(COVERAGE_FLAGS) $(ALIASING_FLAGS) $(NOEXCEPTION_FLAGS) \ > > -- > # Native compiler for the build machine and its switches. > CC_FOR_BUILD =3D $(CC) > CXX_FOR_BUILD =3D $(CXX) > NO_PIE_CFLAGS_FOR_BUILD =3D > NO_PIE_FLAG_FOR_BUILD =3D > BUILD_CFLAGS=3D $(ALL_CFLAGS) $(GENERATOR_CFLAGS) -DGENERATOR_FILE > BUILD_CXXFLAGS =3D $(ALL_CXXFLAGS) $(GENERATOR_CFLAGS) -DGENERATOR_FILE > BUILD_NO_PIE_CFLAGS =3D $(NO_PIE_CFLAGS) > BUILD_CFLAGS +=3D $(BUILD_NO_PIE_CFLAGS) > BUILD_CXXFLAGS +=3D $(BUILD_NO_PIE_CFLAGS) > > # Native compiler that we use. This may be C++ some day. > COMPILER_FOR_BUILD =3D $(CXX_FOR_BUILD) > BUILD_COMPILERFLAGS =3D $(BUILD_CXXFLAGS) > > # Native linker that we use. > LINKER_FOR_BUILD =3D $(CXX_FOR_BUILD) > BUILD_LINKERFLAGS =3D $(BUILD_CXXFLAGS) > > # Native linker and preprocessor flags. For x-fragment overrides. > BUILD_LDFLAGS=3D$(LDFLAGS) > BUILD_NO_PIE_FLAG =3D $(NO_PIE_FLAG) > BUILD_LDFLAGS +=3D $(BUILD_NO_PIE_FLAG) > BUILD_CPPFLAGS=3D -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \ > -I$(srcdir)/../include $(CPPINC) $(CPPFLAGS) > -- > # This is the variable actually used when we compile. If you change this, > # you probably want to update BUILD_CFLAGS in configure.ac > ALL_CFLAGS =3D $(T_CFLAGS) $(CFLAGS-$@) \ > > build/%.o : # dependencies provided by explicit rule later > $(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS)= \ > -o $@ $< > > ^^^^ this has > $(CXX) -c $(ALL_CXXFLAGS) $(GENERATOR_CFLAGS) -DGENERATOR_FILE $(BUILD_NO= _PIE_CFLAGS) $(BUILD_CPPFLAGS) > NO_PIE_CFLAGS_FOR_BUILD is apparently ignored > > # Rule for the generator programs: > $(genprog:%=3Dbuild/gen%$(build_exeext)): build/gen%$(build_exeext): buil= d/gen%.o $(BUILD_LIBDEPS) > +$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) -o $@ = \ > $(filter-out $(BUILD_LIBDEPS), $^) $(BUILD_LIBS) > > -- > build/genversion$(build_exeext): build/genversion.o > +$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) \ > build/genversion.o -o $@ > =3D=3D=3D=3D=3D=3D=3D=3D=3D > > # The name of the compiler to use. > COMPILER =3D $(CXX) > COMPILER_FLAGS =3D $(CXXFLAGS) > # If HOST_LIBS is set, then the user is controlling the libraries to > -- > CET_HOST_FLAGS =3D -fcf-protection > COMPILER +=3D $(CET_HOST_FLAGS) > > -- > # We don't want to compile the compilers with -fPIE, it make PCH fail. > COMPILER +=3D $(NO_PIE_CFLAGS) > > -- > # A list of all the language-specific executables. > COMPILERS =3D gnat1$(exeext) cc1$(exeext) cc1plus$(exeext) d21$(exeext) = f951$(exeext) go1$(exeext) lto1$(exeext) cc1obj$(exeext) cc1objplus$(exeex= t) > > -- > # Native compiler that we use. This may be C++ some day. > COMPILER_FOR_BUILD =3D $(CXX_FOR_BUILD) > BUILD_COMPILERFLAGS =3D $(BUILD_CXXFLAGS) > > -- > > # This is the variable to use when using $(COMPILER). > ALL_COMPILERFLAGS =3D $(ALL_CXXFLAGS) > > -- > > COMPILE.base =3D $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) -o $= @ > > This is : > $(CXX) (NO_PIE_CFLAGS) -c $(ALL_CXXFLAGS) etc. > > COMPILE =3D $(COMPILE.base) -MT $@ -MMD -MP -MF $(@D)/$(DEPDIR)/$(*F).TPo > POSTCOMPILE =3D @mv $(@D)/$(DEPDIR)/$(*F).TPo $(@D)/$(DEPDIR)/$(*F).Po > > .cc.o .c.o: > $(COMPILE) $< > $(POSTCOMPILE) > --=20 H.J.