From patchwork Thu Apr 6 11:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yash Shinde X-Patchwork-Id: 67455 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6B993857702 for ; Thu, 6 Apr 2023 11:34:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6B993857702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680780848; bh=yWKQYbULAifYoEFdJHvqPLOU7QTkIsAUpx/P4V84Gq4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=tCZhu/YmWVrHiIhBegMwctVFTycuRZLyLwBtDAr5viuQdjsb/Ttw1L12N5V1NTtW3 TLZElrbK2qTexULHBmSwuTRlKu2QvdwZoJAvDVUlJuigNNBwefiNNBRBJ+wv1u5EJy xKoD+SFhRuCZ0JJotFjU2/B/iniHL7Ppf1kk/qi8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 91F1A3858D32 for ; Thu, 6 Apr 2023 11:33:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91F1A3858D32 Received: by mail-pj1-x1031.google.com with SMTP id j14-20020a17090a7e8e00b002448c0a8813so1536126pjl.0 for ; Thu, 06 Apr 2023 04:33:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680780819; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yWKQYbULAifYoEFdJHvqPLOU7QTkIsAUpx/P4V84Gq4=; b=Zq1UkyjuC7euWP0NCZzL5RTOOmGi1MrqO5ZTURCGakL3E654NSTKFlbY1413x3QmHi ARbTU+WPnnbNst/3B5OO+5GWVcsTucS/yV+OVGJzN9s98MeE+ZXA04Sg/1KgSwGgX1U0 j8waHefa/7IqAZppm6aO26q7tmNOwAJNuEzETzqOq4QNChajyzicu4D51M71a18oWOD2 NFXkAxdgP2g8D9xdfvqb0byOdhKFJT3wUFO+kt8h9EF+TUplbt55fRdrNeB2aZyNU2bR egpmqnVgCiMU06y7MscITw4SlJl6LLjw7ptkj4VwHZWkV/aqaIcL/dHh/NNYeXifhXmY Sx/g== X-Gm-Message-State: AAQBX9fNGbW1Ps0GBBF1waKVj49oZW/oMiLqJCEy0EL+10MTv2bmz8U8 XpSt7izB76x8zGjGmYSsm47S4pz4jh8WpA== X-Google-Smtp-Source: AKy350beUhBf7x3cAzPYJERkyK0ZTI255qSBFMRpur2O7dsU4Q4K8a7lD8EdZFaJJ0GYfFhYGEBUcw== X-Received: by 2002:a05:6a20:b227:b0:d8:fd3b:f1ba with SMTP id eh39-20020a056a20b22700b000d8fd3bf1bamr2583950pzb.3.1680780819185; Thu, 06 Apr 2023 04:33:39 -0700 (PDT) Received: from bft-2.. ([49.204.85.206]) by smtp.gmail.com with ESMTPSA id b6-20020aa78106000000b0062df30c7e7esm1178595pfi.136.2023.04.06.04.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 04:33:38 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: raj.khem@gmail.com, Yash.Shinde@windriver.com Subject: [PATCH] Add ssp_nonshared to link commandline for musl targets Date: Thu, 6 Apr 2023 17:03:22 +0530 Message-Id: <20230406113322.3182296-1-yashinde145@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Yash Shinde via Gcc-patches From: Yash Shinde Reply-To: Yash Shinde Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Khem Raj When -fstack-protector options are enabled we need to link with ssp_shared on musl since it does not provide the __stack_chk_fail_local() so essentially it provides libssp but not libssp_nonshared something like TARGET_LIBC_PROVIDES_SSP_BUT_NOT_SSP_NONSHARED where-as for glibc the needed symbols are already present in libc_nonshared library therefore we do not need any library helper on glibc based systems but musl needs the libssp_noshared from gcc Signed-off-by: Khem Raj Signed-off-by: Yash Shinde --- gcc/config/linux.h | 7 +++++++ gcc/config/rs6000/linux.h | 10 ++++++++++ gcc/config/rs6000/linux64.h | 10 ++++++++++ 3 files changed, 27 insertions(+) --- gcc/config/linux.h | 7 +++++++ gcc/config/rs6000/linux.h | 10 ++++++++++ gcc/config/rs6000/linux64.h | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/gcc/config/linux.h b/gcc/config/linux.h index e3aca79cccc..33f9265bb93 100644 --- a/gcc/config/linux.h +++ b/gcc/config/linux.h @@ -189,6 +189,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see } #endif +#ifdef TARGET_LIBC_PROVIDES_SSP +#undef LINK_SSP_SPEC +#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ + "|fstack-protector-strong|fstack-protector-explicit" \ + ":-lssp_nonshared}" +#endif + #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */ /* This is a *uclinux* target. We don't define below macros to normal linux versions, because doing so would require *uclinux* targets to include diff --git a/gcc/config/rs6000/linux.h b/gcc/config/rs6000/linux.h index 5d21befe8e4..4fc17e781ba 100644 --- a/gcc/config/rs6000/linux.h +++ b/gcc/config/rs6000/linux.h @@ -99,6 +99,16 @@ " -m elf32ppclinux") #endif +/* link libssp_nonshared.a with musl */ +#if DEFAULT_LIBC == LIBC_MUSL +#ifdef TARGET_LIBC_PROVIDES_SSP +#undef LINK_SSP_SPEC +#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ + "|fstack-protector-strong|fstack-protector-explicit" \ + ":-lssp_nonshared}" +#endif +#endif + #undef LINK_OS_LINUX_SPEC #define LINK_OS_LINUX_SPEC LINK_OS_LINUX_EMUL " %{!shared: %{!static: \ %{!static-pie: \ diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h index 9e457033d11..49c9f6e2105 100644 --- a/gcc/config/rs6000/linux64.h +++ b/gcc/config/rs6000/linux64.h @@ -377,6 +377,16 @@ extern int dot_symbols; " -m elf64ppc") #endif +/* link libssp_nonshared.a with musl */ +#if DEFAULT_LIBC == LIBC_MUSL +#ifdef TARGET_LIBC_PROVIDES_SSP +#undef LINK_SSP_SPEC +#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ + "|fstack-protector-strong|fstack-protector-explicit" \ + ":-lssp_nonshared}" +#endif +#endif + #define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " %{!shared: %{!static: \ %{!static-pie: \ %{rdynamic:-export-dynamic} \