From patchwork Thu Feb 12 21:40:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 439338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AB09614017F for ; Fri, 13 Feb 2015 08:40:57 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; q= dns; s=default; b=Axje2X8RpTwn8SQ8BmZQQC9l9H5qirUdf6hhwDNd8Se82h /ni+J4iijGI0DfcsZ1AT3CiMzxazfr3C7KeLDgQ6WVhyUC9MsVTSBklsL1XaTXDm OyUeb8CSAuoqMGIcXGsrVLnf9sNyeNSeoDJbkLmHpzTEtfo743pQBzAR+Nqwk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; s= default; bh=PFNqj8I4mfr6Flm7fxUVIVSVZiw=; b=n1gKMkeSTVOqDOqiSA6/ DxTVK7iejnAZNNL+9cubHeorZncv+JDhxSjCaahOTu9ewg7nhnwK52gUrnDcfFkt rUY6AhxRQwcSXWgKbS2jzve/q9Y483yfMWx+DI+w6TROFURd66nCELoWnjdlAbQ3 spwkqFXUgCTJ38iiLERxaUo= Received: (qmail 14983 invoked by alias); 12 Feb 2015 21:40:52 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 14973 invoked by uid 89); 12 Feb 2015 21:40:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [COMMITTED PATCH] Support after-link variable to run a final step on binaries. Message-Id: <20150212214047.223602C3C23@topped-with-meat.com> Date: Thu, 12 Feb 2015 13:40:47 -0800 (PST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=odHwp6aQd4UO4KznjegA:9 a=CjuIK1q_8ugA:10 I'm using this in the NaCl port to do a post-link validation step. You can set it configparms to do some other random thing. Nothing about the build is changed if you don't set the new variable. Thanks, Roland 2015-02-12 Roland McGrath * Makeconfig (after-link): New variable. (+link-pie, +link-pie-tests): Use it. (+link-static, +link-static-tests): Likewise. (+link, +link-tests): Likewise. * Makerules (build-module, build-module-asneeded): Likewise. (lib%.so, $(common-objpfx)libc.so, $(common-objpfx)linkobj/libc.so): Likewise. * elf/Makefile ($(objpfx)ld.so): Likewise. --- a/Makeconfig +++ b/Makeconfig @@ -387,6 +387,14 @@ LDFLAGS.so += $(hashstyle-LDFLAGS) LDFLAGS-rtld += $(hashstyle-LDFLAGS) endif +# Command to run after every final link (executable or shared object). +# This is invoked with $(call after-link,...), so it should operate on +# the file $1. This can be set to do some sort of post-processing on +# binaries, or to perform some sort of static sanity check. +ifndef after-link +after-link = +endif + # Command for linking PIE programs with the C library. ifndef +link-pie +link-pie-before-libc = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \ @@ -400,10 +408,15 @@ ifndef +link-pie $(common-objpfx)libc% $(+postinit),$^) \ $(link-extra-libs) +link-pie-after-libc = $(+postctorS) $(+postinit) -+link-pie = $(+link-pie-before-libc) $(rtld-LDFLAGS) $(link-libc) \ - $(+link-pie-after-libc) -+link-pie-tests = $(+link-pie-before-libc) $(rtld-tests-LDFLAGS) \ - $(link-libc-tests) $(+link-pie-after-libc) +define +link-pie +$(+link-pie-before-libc) $(rtld-LDFLAGS) $(link-libc) $(+link-pie-after-libc) +$(call after-link,$@) +endef +define +link-pie-tests +$(+link-pie-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \ + $(+link-pie-after-libc) +$(call after-link,$@) +endef endif # Command for statically linking programs with the C library. ifndef +link-static @@ -417,10 +430,14 @@ ifndef +link-static $(common-objpfx)libc% $(+postinit),$^) \ $(link-extra-libs-static) +link-static-after-libc = $(+postctorT) $(+postinit) -+link-static = $(+link-static-before-libc) $(link-libc-static) \ - $(+link-static-after-libc) -+link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \ - $(+link-static-after-libc) +define +link-static +$(+link-static-before-libc) $(link-libc-static) $(+link-static-after-libc) +$(call after-link,$@) +endef +define +link-static-tests +$(+link-static-before-libc) $(link-libc-static-tests) $(+link-static-after-libc) +$(call after-link,$@) +endef endif # Commands for linking programs with the C library. ifndef +link @@ -436,10 +453,15 @@ ifeq (yes,$(build-shared)) $(common-objpfx)libc% $(+postinit),$^) \ $(link-extra-libs) +link-after-libc = $(+postctor) $(+postinit) -+link = $(+link-before-libc) $(rtld-LDFLAGS) $(link-libc) \ - $(+link-after-libc) -+link-tests = $(+link-before-libc) $(rtld-tests-LDFLAGS) \ - $(link-libc-tests) $(+link-after-libc) +define +link +$(+link-before-libc) $(rtld-LDFLAGS) $(link-libc) $(+link-after-libc) +$(call after-link,$@) +endef +define +link-tests +$(+link-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \ + $(+link-after-libc) +$(call after-link,$@) +endef else +link = $(+link-static) +link-tests = $(+link-static-tests) --- a/Makerules +++ b/Makerules @@ -505,6 +505,7 @@ link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \ # to be as similar as possible to a default link with an installed libc. lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps) $(build-shlib) $(link-libc-args) + $(call after-link,$@) define build-shlib-helper $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \ @@ -580,12 +581,14 @@ endef define build-module $(build-module-helper) -o $@ $(shlib-lds-flags) \ $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args) +$(call after-link,$@) endef define build-module-asneeded $(build-module-helper) -o $@ $(shlib-lds-flags) \ $(csu-objpfx)abi-note.o \ -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \ $(link-libc-args) +$(call after-link,$@) endef build-module-helper-objlist = \ @@ -666,6 +669,7 @@ $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \ $(elf-objpfx)ld.so \ $(shlib-lds) $(build-shlib) + $(call after-link,$@) $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \ $(common-objpfx)linkobj/libc_pic.a \ @@ -674,6 +678,7 @@ $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \ $(elf-objpfx)ld.so \ $(shlib-lds) $(build-shlib) + $(call after-link,$@) ifeq ($(build-shared),yes) $(common-objpfx)libc.so: $(common-objpfx)libc.map --- a/elf/Makefile +++ b/elf/Makefile @@ -349,6 +349,7 @@ $(objpfx)ld.so: $(objpfx)librtld.os $(ld-map) $(filter-out $(map-file),$^) $(load-map-file) \ -Wl,-soname=$(rtld-installed-name) \ -Wl,-defsym=_begin=0 + $(call after-link,$@.new) $(READELF) -s $@.new \ | $(AWK) '($$7 ~ /^UND(|EF)$$/ && $$1 != "0:" && $$4 != "REGISTER") { print; p=1 } END { exit p != 0 }' mv -f $@.new $@