From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtprelay04.ispgateway.de (smtprelay04.ispgateway.de [80.67.31.38]) by sourceware.org (Postfix) with ESMTPS id 97D823858430 for ; Fri, 15 Dec 2023 17:15:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97D823858430 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=schwinge.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=schwinge.name ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 97D823858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=80.67.31.38 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702660545; cv=none; b=tI/zYh4TfBk0g6WqrMbEkHsHSp/qtB7YDmTk8spt/pO3mY0mQbq61F5F21uvGLJm0RYkWx1CAfKxW3Nhx52np+ZHGU0LEVNFcch0TMZ5m9yg0jsMRyoDrmSTeek7ZmKKhnyoVjntQN1uIXIZNV8zjD6IMeb/LS0E8qNm4Y/Hfyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702660545; c=relaxed/simple; bh=7jKjjSMAxmjsvWTh/XE/Y07rKccnXJlYvHNkcRt/99Y=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OENTiH8vE5S99+TeuOdK7Ak7dh0ktJRbwAh9WZ5eliz3q/E3k0lxags4AVD/2Ulj9yxj/RgLaSl6XyqRMFPw9kgtuXuITOnzmuDlsp9GPl7+l2pi1NrN3nzPbAnmM/4KPxUc7kC0GHR/Iwo19Sc1Nr3IkISV3QEqw2hoAtPFcWw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [93.210.54.129] (helo=euler.schwinge.homeip.net) by smtprelay04.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.1) (envelope-from ) id 1rEBmn-0003BF-1j; Fri, 15 Dec 2023 18:15:41 +0100 Received: (nullmailer pid 488576 invoked by uid 1000); Fri, 15 Dec 2023 17:15:40 -0000 From: Thomas Schwinge To: Hanke Zhang Cc: gcc@gcc.gnu.org Subject: Re: Question about creating global varaiable during IPA PASS. In-Reply-To: References: User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Fri, 15 Dec 2023 18:15:37 +0100 Message-ID: <87le9vs7ye.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Df-Sender: b3V0Z29pbmdAc2Nod2luZ2UubmFtZQ== X-Spam-Status: No, score=-44.5 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Hanke! On 2023-12-13T17:04:57+0800, Hanke Zhang via Gcc wrote: > Hi, I'm trying to create a global variable in my own PASS which > located at the LATE_IPA_PASSES. (I'm using GCC 10.3.0.) I can't comment on IPA aspects, or whether something was different on oldish GCC 10 (why using that one, by the way?), and I've not actually verified what you're doing here: > And after creating it, I added the attributes like the following. > > // 1. create the var > tree new_name =3D get_identifier (xx); > tree new_type =3D build_pointer_type (xx); > tree new_var =3D build_decl (UNKNOWN_LOCATION, VAR_DECL, new_name, new_ty= pe); > add_attributes (new_var); > > static void > add_attributes (tree var) > { > DECL_ARTIFICIAL (var) =3D 1; > DECL_EXTERNAL (var) =3D 0; > TREE_STATIC (var) =3D 1; > TREE_PUBLIC (var) =3D 1; > TREE_USED (var) =3D 1; > DECL_CONTEXT (var) =3D NULL_TREE; > TREE_THIS_VOLATILE (var) =3D 0; > TREE_ADDRESSABLE (var) =3D 0; > TREE_READONLY (var) =3D 0; > if (is_global_var (var)) > set_decl_tls_model (var, TLS_MODEL_NONE); > } > > But when I try to compile some example files with -flto, error occurs. > > /usr/bin/ld: xxx.ltrans0.ltrans.o: in function `xxx': > xxx.c: undefined reference to `glob_var' > xxx.c: undefined reference to `glob_var' > xxx.c: undefined reference to `glob_var' > > Here `glob_var' is the global varaiable created in my PASS. > > I would like to ask, am I using some attributes incorrectly? ..., but are you maybe simply missing to 'varpool_node::add (var);' or 'varpool_node::finalize_decl (var);' or something like that? See other uses of those, and description in 'gcc/cgraph.h', 'struct [...] varpool_node': /* Add the variable DECL to the varpool. Unlike finalize_decl function is intended to be used by middle end and allows insertion of new variable at arbitrary po= int of compilation. */ static void add (tree decl); /* Mark DECL as finalized. By finalizing the declaration, frontend i= nstruct the middle end to output the variable to asm file, if needed or ex= ternally visible. */ static void finalize_decl (tree decl); If that's not it, we'll have to look in more detail. Gr=C3=BC=C3=9Fe Thomas