ARF
ARF

Reputation: 7694

Can llvm aliases be used for inter-module or only intra-module?

LLVM defines aliases for global values:

@<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>

What are valid <Aliasee> values?

  1. Only names that occur somewhere else in the current modules or
  2. also names that occur in other modules that are linked in later?

I thought inter-module aliases were permitted but I cannot get it to work. I keep getting errors of this type:

<string>:5:39: error: use of undefined value '@my_name'
@"MyAlias" = external alias i32, i32* @my_name
                                      ^

Note: @my_name is not defined in the current module. It is defined in another module.

Upvotes: 0

Views: 267

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

Anything represented in LLVM IR needs to be declared. Your my_name should be declared as well. Note, however, that aliases are created to the existing definition. See the section "Restrictions" in the manual:

Since aliases are only a second name, some restrictions apply, of which some can only be checked when producing an object file:

  • The expression defining the aliasee must be computable at assembly time. Since it is just a name, no relocations can be used.
  • No alias in the expression can be weak as the possibility of the intermediate alias being overridden cannot be represented in an object file.
  • No global value in the expression can be a declaration, since that would require a relocation, which is not possible.

Upvotes: 0

Related Questions