public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hanke Zhang <hkzhang455@gmail.com>
To: gcc@gcc.gnu.org
Subject: Question about creating global varaiable during IPA PASS.
Date: Wed, 13 Dec 2023 17:04:57 +0800	[thread overview]
Message-ID: <CAM_DAs9XZXf30V4vzrC_ZbHGemq2zQcibetAgoTUd6m59bJRWA@mail.gmail.com> (raw)

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.)

And after creating it, I added the attributes like the following.

// 1. create the var
tree new_name = get_identifier (xx);
tree new_type = build_pointer_type (xx);
tree new_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, new_name, new_type);
add_attributes (new_var);

static void
add_attributes (tree var)
{
DECL_ARTIFICIAL (var) = 1;
DECL_EXTERNAL (var) = 0;
TREE_STATIC (var) = 1;
TREE_PUBLIC (var) = 1;
TREE_USED (var) = 1;
DECL_CONTEXT (var) = NULL_TREE;
TREE_THIS_VOLATILE (var) = 0;
TREE_ADDRESSABLE (var) = 0;
TREE_READONLY (var) = 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?

Thanks
Hanke Zhang

             reply	other threads:[~2023-12-13  9:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-13  9:04 Hanke Zhang [this message]
2023-12-15 17:15 ` Thomas Schwinge
2023-12-21  7:27   ` Hanke Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAM_DAs9XZXf30V4vzrC_ZbHGemq2zQcibetAgoTUd6m59bJRWA@mail.gmail.com \
    --to=hkzhang455@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).