From patchwork Tue Nov 5 11:34:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Malcomson X-Patchwork-Id: 1189600 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512434-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="T5f6iiMY"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="ym+4B++G"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="ym+4B++G"; dkim-atps=neutral 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 476ndv48X9z9sNT for ; Tue, 5 Nov 2019 22:35:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; q=dns; s=default; b=jxJ04AfkaY/3H6oi XGCNvVcDBcjaicArOqu29bPHBmJxse6fDPIQTcwYJagGupM+gaojDIwelbvNmo2T 4uFoBCJd+B/9Kk3WcNsFpLSL15YccwnCPsP8g0SagTL/O4FdglT5SW6xg1XZ3Ks5 84OxUj28uHY2EiOHSN0WgsfaJMI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; s=default; bh=5izTq7DSFDyuHQ6S0hyRRt BBLms=; b=T5f6iiMYD8AdMm2vBKgMzUCFnKKzFEj9VcYoew9T/yslLuN9g6ADcU yypId1xMa9dc1p5hHiLf9gyvg1nMoS8OW1FQOer9oNLukyj8b2FaHGHiWt7u3h6u cy2W+ze23akjnO3kNxo/syhLBzUVvKS2J9kvCLpFdmgbseJq2Fg1M= Received: (qmail 84345 invoked by alias); 5 Nov 2019 11:34:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 84216 invoked by uid 89); 5 Nov 2019 11:34:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.0 required=5.0 tests=AWL, BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: FRA01-MR2-obe.outbound.protection.outlook.com Received: from mail-eopbgr90049.outbound.protection.outlook.com (HELO FRA01-MR2-obe.outbound.protection.outlook.com) (40.107.9.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Nov 2019 11:34:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lK87kfQ7ZucQxBEo9pdVdTBMrjjmVDmAS06zTZ7dMW8=; b=ym+4B++GJQFMfxL+Pt2q0Tx6T1/o5BiT5ojgZRh+PWDND4uZMX1REYGlp09SJFctNeaZKVWWFig5D62H6nFmxNcQn5IJ9UiRr6sokIcH1GsvyR43iDzosP+IZPN9lzhD8pkRwWyl+atvbGwLT2ROTjryERQot53sLh64MRRIIRw= Received: from VI1PR08CA0195.eurprd08.prod.outlook.com (2603:10a6:800:d2::25) by PR2PR08MB4922.eurprd08.prod.outlook.com (2603:10a6:101:27::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Tue, 5 Nov 2019 11:34:09 +0000 Received: from DB5EUR03FT025.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::200) by VI1PR08CA0195.outlook.office365.com (2603:10a6:800:d2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2408.24 via Frontend Transport; Tue, 5 Nov 2019 11:34:09 +0000 Authentication-Results: spf=fail (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received-SPF: Fail (protection.outlook.com: domain of arm.com does not designate 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT025.mail.protection.outlook.com (10.152.20.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2387.20 via Frontend Transport; Tue, 5 Nov 2019 11:34:08 +0000 Received: ("Tessian outbound 0cf06bf5c60e:v33"); Tue, 05 Nov 2019 11:34:08 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 58a1dcfb2b351e44 X-CR-MTA-TID: 64aa7808 Received: from bb8ebd552295.2 (cr-mta-lb-1.cr-mta-net [104.47.14.55]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id A52D44F6-E863-4A04-9358-F6FF5312EA74.1; Tue, 05 Nov 2019 11:34:03 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2055.outbound.protection.outlook.com [104.47.14.55]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id bb8ebd552295.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 Nov 2019 11:34:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W02LYBGzy78KL4LiLvwRm8JEYUi+Gta6HArdaNOE2Fu5SfC3Vjk+tBbjNe6XuAskx9IcRozNBa5zJ72ldrwkXUwJrqFz5K1tT18aZQp23IbOJODbvPhQn+HjUN2d+yu3E3dZQ9zkqK4387hcqK5W4aO068ijlUIp+9hOYCBMB+mpZuyFbWGMF7NHqPOeg2fcGLppeDjiqKtAgmtE/swYaXVMWF3GWDIAByweotDP37vxFFZo8DiFoFVDKf+JW2pvDzOsJf2TFY2y3MrM5xhVCvAaxEGxYyEjozCKNkjka/kpjE/x6J5gT5MbJ5ZvEi+r/FjdNeo+aXhVb7pZBbiVOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lK87kfQ7ZucQxBEo9pdVdTBMrjjmVDmAS06zTZ7dMW8=; b=jnSvxQJoy9Hvnho7MCw89m2M5QgPjQSuEFnxdgfL9gjM4Q8ckZDP1ybSaHVBjwC9e/1wdud+cIz0QKmw6onaN/kH8dgPTJuNEA5HOcSj/H7GvkBNwCL0ApmLsX4XxpxhbWviMrQFCIi1ik+o4bP06ZeTX6RilX1kCDEvjOCZIdwJoagbyD+6hgxcSTOLNKMKyOFpuExrHbYl/JKzqdbv4R6lyRSBo3wZtTvgTAoMaWFhfK/T1vhb6/h7Y02aRElpGtYGvdrei/auisT91bRSaA8NZHqS3exPHSUJOiCfl/tOvM9TuUJoIP7/7BB0jOphqxW3RBvRzune2IngKvMCFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lK87kfQ7ZucQxBEo9pdVdTBMrjjmVDmAS06zTZ7dMW8=; b=ym+4B++GJQFMfxL+Pt2q0Tx6T1/o5BiT5ojgZRh+PWDND4uZMX1REYGlp09SJFctNeaZKVWWFig5D62H6nFmxNcQn5IJ9UiRr6sokIcH1GsvyR43iDzosP+IZPN9lzhD8pkRwWyl+atvbGwLT2ROTjryERQot53sLh64MRRIIRw= Received: from HE1PR0802MB2251.eurprd08.prod.outlook.com (10.172.131.21) by HE1PR0802MB2313.eurprd08.prod.outlook.com (10.172.127.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Tue, 5 Nov 2019 11:34:01 +0000 Received: from HE1PR0802MB2251.eurprd08.prod.outlook.com ([fe80::e120:9a38:bcf4:6075]) by HE1PR0802MB2251.eurprd08.prod.outlook.com ([fe80::e120:9a38:bcf4:6075%5]) with mapi id 15.20.2408.024; Tue, 5 Nov 2019 11:34:01 +0000 From: Matthew Malcomson To: "gcc-patches@gcc.gnu.org" CC: nd , "kcc@google.com" , "dvyukov@google.com" , Martin Liska , Richard Earnshaw , Kyrylo Tkachov , "dodji@redhat.com" , "jakub@redhat.com" Subject: [PATCH 5/X] [libsanitizer] Remove system allocator fallback Date: Tue, 5 Nov 2019 11:34:01 +0000 Message-ID: References: <157295142743.27946.1142544630216676787.scripted-patch-series@arm.com> In-Reply-To: <157295142743.27946.1142544630216676787.scripted-patch-series@arm.com> Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Matthew.Malcomson@arm.com; x-ms-exchange-transport-forked: True x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:9508;OLM:9508; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(979002)(4636009)(376002)(136003)(396003)(366004)(39860400002)(346002)(54534003)(189003)(199004)(11346002)(446003)(66616009)(5660300002)(26005)(102836004)(7696005)(2501003)(6506007)(7736002)(8676002)(81156014)(81166006)(33656002)(478600001)(74316002)(2906002)(76176011)(186003)(386003)(99936001)(8936002)(14454004)(2351001)(44832011)(486006)(476003)(66476007)(316002)(52116002)(71190400001)(6116002)(25786009)(3846002)(305945005)(54906003)(86362001)(66066001)(9686003)(6436002)(5024004)(5640700003)(4326008)(55016002)(99286004)(14444005)(66446008)(71200400001)(66556008)(52536014)(66946007)(64756008)(256004)(6916009)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0802MB2313; H:HE1PR0802MB2251.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Eqt+EeQWp3oqbUFQKQ49fFvysuNRydKjyESYbVfwQZfN6N3FrcDQrhUXs6bAHAQiwX8AOzJTJNyHq4z7/IW9FQUaY3sKDZBfY8BPOT6hqSM7Q2cR1OuPnK13piSb2WWbU/Tib/eCYkhkQGCUfuz9SHnF2hGA8sJhplD2MY2t6JMXig/6WbYCevmTcGfIjzX2RNZ4B0fmQTEuqFkUBewY19Z7TQJVwpEMVRtMDtjPvqiGmbM9dsl3sKyZafuuLS1Chy5uDMDqZbka65YNUrfgXBpUyjspDZCsIatQIh9vGwCX77Ncmtu0Re3f+Fck+DoTLzSM+xBMMaC2vudBvQF1aLn4Z8ssZGZ44fAB2lK4Wxz4BASA4o3mt3U16EtpmuuaCVF3Jdy+01GxiHLGEYfKsIi5l3KgooM+htCJi/14+k0KFvlw8Lgf55r7qy34i2pc MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Matthew.Malcomson@arm.com; X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 398aa754-8082-4e25-00ac-08d761e40df1 X-IsSubscribed: yes Backport from llvm-svn: 375296. This was an experiment made possible by a non-standard feature of the Android dynamic loader. Going without that experiment makes implementation for glibc easier. libsanitizer/ChangeLog: 2019-11-05 Matthew Malcomson * hwasan/hwasan_allocator.cpp (hwasan_realloc, hwasan_free, __hwasan_disable_allocator_tagging): Remove allocator fallback. * hwasan/hwasan_allocator.h (free, realloc): Remove REAL declarations. * hwasan/hwasan_interceptors.cpp (free, realloc): Remove interceptors. ############### Attachment also inlined for ease of reply ############### diff --git a/libsanitizer/hwasan/hwasan_allocator.h b/libsanitizer/hwasan/hwasan_allocator.h index 3a50a11f352600d82aaaf73ddd7a5595e9f8a4d5..f62be269602143679f9f7abc9ec4a8a08dad207f 100644 --- a/libsanitizer/hwasan/hwasan_allocator.h +++ b/libsanitizer/hwasan/hwasan_allocator.h @@ -13,7 +13,6 @@ #ifndef HWASAN_ALLOCATOR_H #define HWASAN_ALLOCATOR_H -#include "interception/interception.h" #include "sanitizer_common/sanitizer_allocator.h" #include "sanitizer_common/sanitizer_allocator_checks.h" #include "sanitizer_common/sanitizer_allocator_interface.h" @@ -26,11 +25,6 @@ #error Unsupported platform #endif -#if HWASAN_WITH_INTERCEPTORS -DECLARE_REAL(void *, realloc, void *ptr, uptr size) -DECLARE_REAL(void, free, void *ptr) -#endif - namespace __hwasan { struct Metadata { diff --git a/libsanitizer/hwasan/hwasan_allocator.cpp b/libsanitizer/hwasan/hwasan_allocator.cpp index b4fae5820d0a1749663f251c7a3f1dc841741aed..81a57d3afd4d364dca96f20df3e94014483b6df1 100644 --- a/libsanitizer/hwasan/hwasan_allocator.cpp +++ b/libsanitizer/hwasan/hwasan_allocator.cpp @@ -22,11 +22,6 @@ #include "hwasan_thread.h" #include "hwasan_report.h" -#if HWASAN_WITH_INTERCEPTORS -DEFINE_REAL(void *, realloc, void *ptr, uptr size) -DEFINE_REAL(void, free, void *ptr) -#endif - namespace __hwasan { static Allocator allocator; @@ -301,14 +296,6 @@ void *hwasan_calloc(uptr nmemb, uptr size, StackTrace *stack) { void *hwasan_realloc(void *ptr, uptr size, StackTrace *stack) { if (!ptr) return SetErrnoOnNull(HwasanAllocate(stack, size, sizeof(u64), false)); - -#if HWASAN_WITH_INTERCEPTORS - // A tag of 0 means that this is a system allocator allocation, so we must use - // the system allocator to realloc it. - if (!flags()->disable_allocator_tagging && GetTagFromPointer((uptr)ptr) == 0) - return REAL(realloc)(ptr, size); -#endif - if (size == 0) { HwasanDeallocate(stack, ptr); return nullptr; @@ -381,13 +368,6 @@ int hwasan_posix_memalign(void **memptr, uptr alignment, uptr size, } void hwasan_free(void *ptr, StackTrace *stack) { -#if HWASAN_WITH_INTERCEPTORS - // A tag of 0 means that this is a system allocator allocation, so we must use - // the system allocator to free it. - if (!flags()->disable_allocator_tagging && GetTagFromPointer((uptr)ptr) == 0) - return REAL(free)(ptr); -#endif - return HwasanDeallocate(stack, ptr); } @@ -400,15 +380,6 @@ void __hwasan_enable_allocator_tagging() { } void __hwasan_disable_allocator_tagging() { -#if HWASAN_WITH_INTERCEPTORS - // Allocator tagging must be enabled for the system allocator fallback to work - // correctly. This means that we can't disable it at runtime if it was enabled - // at startup since that might result in our deallocations going to the system - // allocator. If tagging was disabled at startup we avoid this problem by - // disabling the fallback altogether. - CHECK(flags()->disable_allocator_tagging); -#endif - atomic_store_relaxed(&hwasan_allocator_tagging_enabled, 0); } diff --git a/libsanitizer/hwasan/hwasan_interceptors.cpp b/libsanitizer/hwasan/hwasan_interceptors.cpp index f6758efa65c051376468d3cad2c1530fa7329627..4f9bd3469eb10ca2cf3108326308e45e7a9d38b6 100644 --- a/libsanitizer/hwasan/hwasan_interceptors.cpp +++ b/libsanitizer/hwasan/hwasan_interceptors.cpp @@ -334,8 +334,6 @@ void InitializeInterceptors() { #if !defined(__aarch64__) INTERCEPT_FUNCTION(pthread_create); #endif // __aarch64__ - INTERCEPT_FUNCTION(realloc); - INTERCEPT_FUNCTION(free); #endif inited = 1; diff --git a/libsanitizer/hwasan/hwasan_allocator.h b/libsanitizer/hwasan/hwasan_allocator.h index 3a50a11f352600d82aaaf73ddd7a5595e9f8a4d5..f62be269602143679f9f7abc9ec4a8a08dad207f 100644 --- a/libsanitizer/hwasan/hwasan_allocator.h +++ b/libsanitizer/hwasan/hwasan_allocator.h @@ -13,7 +13,6 @@ #ifndef HWASAN_ALLOCATOR_H #define HWASAN_ALLOCATOR_H -#include "interception/interception.h" #include "sanitizer_common/sanitizer_allocator.h" #include "sanitizer_common/sanitizer_allocator_checks.h" #include "sanitizer_common/sanitizer_allocator_interface.h" @@ -26,11 +25,6 @@ #error Unsupported platform #endif -#if HWASAN_WITH_INTERCEPTORS -DECLARE_REAL(void *, realloc, void *ptr, uptr size) -DECLARE_REAL(void, free, void *ptr) -#endif - namespace __hwasan { struct Metadata { diff --git a/libsanitizer/hwasan/hwasan_allocator.cpp b/libsanitizer/hwasan/hwasan_allocator.cpp index b4fae5820d0a1749663f251c7a3f1dc841741aed..81a57d3afd4d364dca96f20df3e94014483b6df1 100644 --- a/libsanitizer/hwasan/hwasan_allocator.cpp +++ b/libsanitizer/hwasan/hwasan_allocator.cpp @@ -22,11 +22,6 @@ #include "hwasan_thread.h" #include "hwasan_report.h" -#if HWASAN_WITH_INTERCEPTORS -DEFINE_REAL(void *, realloc, void *ptr, uptr size) -DEFINE_REAL(void, free, void *ptr) -#endif - namespace __hwasan { static Allocator allocator; @@ -301,14 +296,6 @@ void *hwasan_calloc(uptr nmemb, uptr size, StackTrace *stack) { void *hwasan_realloc(void *ptr, uptr size, StackTrace *stack) { if (!ptr) return SetErrnoOnNull(HwasanAllocate(stack, size, sizeof(u64), false)); - -#if HWASAN_WITH_INTERCEPTORS - // A tag of 0 means that this is a system allocator allocation, so we must use - // the system allocator to realloc it. - if (!flags()->disable_allocator_tagging && GetTagFromPointer((uptr)ptr) == 0) - return REAL(realloc)(ptr, size); -#endif - if (size == 0) { HwasanDeallocate(stack, ptr); return nullptr; @@ -381,13 +368,6 @@ int hwasan_posix_memalign(void **memptr, uptr alignment, uptr size, } void hwasan_free(void *ptr, StackTrace *stack) { -#if HWASAN_WITH_INTERCEPTORS - // A tag of 0 means that this is a system allocator allocation, so we must use - // the system allocator to free it. - if (!flags()->disable_allocator_tagging && GetTagFromPointer((uptr)ptr) == 0) - return REAL(free)(ptr); -#endif - return HwasanDeallocate(stack, ptr); } @@ -400,15 +380,6 @@ void __hwasan_enable_allocator_tagging() { } void __hwasan_disable_allocator_tagging() { -#if HWASAN_WITH_INTERCEPTORS - // Allocator tagging must be enabled for the system allocator fallback to work - // correctly. This means that we can't disable it at runtime if it was enabled - // at startup since that might result in our deallocations going to the system - // allocator. If tagging was disabled at startup we avoid this problem by - // disabling the fallback altogether. - CHECK(flags()->disable_allocator_tagging); -#endif - atomic_store_relaxed(&hwasan_allocator_tagging_enabled, 0); } diff --git a/libsanitizer/hwasan/hwasan_interceptors.cpp b/libsanitizer/hwasan/hwasan_interceptors.cpp index f6758efa65c051376468d3cad2c1530fa7329627..4f9bd3469eb10ca2cf3108326308e45e7a9d38b6 100644 --- a/libsanitizer/hwasan/hwasan_interceptors.cpp +++ b/libsanitizer/hwasan/hwasan_interceptors.cpp @@ -334,8 +334,6 @@ void InitializeInterceptors() { #if !defined(__aarch64__) INTERCEPT_FUNCTION(pthread_create); #endif // __aarch64__ - INTERCEPT_FUNCTION(realloc); - INTERCEPT_FUNCTION(free); #endif inited = 1;