From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 403CC3858413 for ; Thu, 21 Dec 2023 07:27:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 403CC3858413 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 403CC3858413 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703143644; cv=none; b=oXYGLRB4E2rEQAmyk/9FfiU4Lnh6R1kF7zs4CRoDJJCcJbGaYOsNdhcgEp+CuTd0D6ZLHfbx2wPhnXJMSonzGrNrd+JStavHda4wugI2mxFZNap3rlb2MYhwB4dYwu01L29+1nHfnw8+1kKFM9JYb73LH6anKzB0X8ZMhL/luzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703143644; c=relaxed/simple; bh=ikWhh4FpmgIh2l44qU/0TUUSjttTd/UHL/03m65p0iI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=ILHOnTwnYYS8uOmIsq5A+4GoflLQOBD7o5tk1HXjf1YLazJFOFTXWL5jehOwrYmz2RT5DzdpChvfjYN/Wk13Fp9jvmMetUA2GVemLuJYW1GBvSi3MjDQlNLxnFU/7W7F0YI09jQhRGcwQ1/cb5y7+liuNGMOer/zBrrhJ4Wqmjg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2cc6121c113so4388091fa.0 for ; Wed, 20 Dec 2023 23:27:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703143642; x=1703748442; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YVt9/zKsozyAYBSwZj3s4ToywNMEKF1sSks1DR30Rdg=; b=ZWc4jezky9mU587ETgaKwdvVEaxhIv1qvLbDwylmJ45Q1ikGmzeHxEh9InsipC49SD L99ZeuVx76tikicE6uaOyFpcru29mMe2BfxZsGjKQxLJQgP9NseobY4HSzs8nnluoRjT +snnwR0spLX5QBFB1NWhaPtNy1flp/pmJ/2H4uFzk5YpFCjGCVz06vcn2daNCLKyfdAB t4LROEmNwcRBx1iqvoIM//Be0mM/fwWbihqDm+mviDhP5A9x63gSnP0Mlh3Yci6IByIF 3u/vy1gMX5TOaZyMXbcBOc6wYIuPBensc3K2F0AsmFY4rzxDSoqh+JeOlOyLs/5nW91t Yhyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703143642; x=1703748442; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YVt9/zKsozyAYBSwZj3s4ToywNMEKF1sSks1DR30Rdg=; b=SAkt3M8eyJntTkxNVF05+/0EOBG3g2UK6tGZdFpHQ16lpEtPU6twEv0X3paLwUXl+S UQB/Ajo8WjUtxaZva8AR6GyCP49hbcVW+u7jQa+GCpT6tphVdXrLMP1ogI67MJJfAv+H flKYZM0oHoei2nUxafgLIg8LZ5SKe+AW+SrYh4Hq/oGXlushibQah079BfuOkKP3xom6 mWRYy+/ZwYuJfV37pMSdAvYOAJj5edXjdL7x6xqnlLVJIAj3k55HTzvoC+gAH9Iyce9J 4MyWweG/Tp7RRHaQfthDlQp05ucuZVvJPTFv5cioTw1JMpEe/TgtzZKwHvuz8mpJwEjr nsAw== X-Gm-Message-State: AOJu0YzIw81QsoPBYc+LbRrmTP0wifusshxtzQJdGEWJSs+OW92wM5wg BUpCqOijN66bBpSa2dwlOGDvDXuPM8ZUK6dqpxSpUH9cwTA= X-Google-Smtp-Source: AGHT+IGnLcNKUIsEv3roobpREXqHsLTfnyBrERh/MSM7ZgNDUWAfIVBQKIvLeNUz1pFLvRP2z9R3Rn7WAfmgVQQUXXQ= X-Received: by 2002:a2e:9355:0:b0:2cc:582f:32 with SMTP id m21-20020a2e9355000000b002cc582f0032mr1839785ljh.209.1703143641391; Wed, 20 Dec 2023 23:27:21 -0800 (PST) MIME-Version: 1.0 References: <87le9vs7ye.fsf@euler.schwinge.homeip.net> In-Reply-To: <87le9vs7ye.fsf@euler.schwinge.homeip.net> From: Hanke Zhang Date: Thu, 21 Dec 2023 15:27:09 +0800 Message-ID: Subject: Re: Question about creating global varaiable during IPA PASS. To: thomas@schwinge.name Cc: gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Thomas! Thanks for your reply. That's exactly what I'm missing. When I add varpool_node::finalize_decl() to my code, everything works fine! Thomas Schwinge =E4=BA=8E2023=E5=B9=B412=E6=9C=8816= =E6=97=A5=E5=91=A8=E5=85=AD 01:15=E5=86=99=E9=81=93=EF=BC=9A > > 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_= type); > > 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 = point > of compilation. */ > static void add (tree decl); > > /* Mark DECL as finalized. By finalizing the declaration, frontend= instruct > the middle end to output the variable to asm file, if needed or = externally > 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