[patch][pr10367] Add support for offsets in GlobalAlias

Duncan P. N. Exon Smith dexonsmith at apple.com
Tue May 20 15:20:19 PDT 2014


On 2014-May-20, at 07:21, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:

> Thanks Reid and Tim.
> 
> An updated patch is attached. The main changes are
> * Update documentation.
> * Make it support 64 bit offsets.
> * Handle offsets pointing out of objects and because of that, use a
> signed offset.
> * Updated globalopt to be aware of offsets.
> 
> The reason I decided to go with Reid's suggestion is that is valid on
> ELF (and on some special cases on MachO) to have a relocation that
> points outside of an object. Given that it seems natural to allow a
> name (alias) for things like "the byte immediately after this string".
> 
> Cheers,
> Rafael

Assuming Reid and Tim sign off, this LGTM with a couple of minor
changes.

> diff --git a/docs/LangRef.rst b/docs/LangRef.rst
> index ceec1bd..daf4b46 100644
> --- a/docs/LangRef.rst
> +++ b/docs/LangRef.rst
> @@ -664,15 +664,17 @@ Syntax::
>  Aliases
>  -------
>  
> -Aliases act as "second name" for the aliasee value (which can be either
> -function, global variable, another alias or bitcast of global value).
> +Aliases act as "second name" for a position in the object file. The
> +position is represented by an aliasee (a funtion or global variable)
> +and an offset.
>  Aliases may have an optional :ref:`linkage type <linkage>`, an optional
>  :ref:`visibility style <visibility>`, and an optional :ref:`DLL storage class
>  <dllstorageclass>`.
>  
>  Syntax::
>  
> -    @<Name> = [Visibility] [DLLStorageClass] alias [Linkage] <AliaseeTy> @<Aliasee>
> +    @<Name> = [Visibility] [DLLStorageClass] alias [Linkage] <AliaseeTy> @<Aliasee> [offset Value]
> +    @<Name> = [Visibility] [DLLStorageClass] alias [Linkage] [AddrSpace] <AliasTy>, <AliaseeTy> @<Aliasee> [offset Value]
>  
>  The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
>  ``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
> @@ -680,7 +682,10 @@ might not correctly handle dropping a weak symbol that is aliased by a non-weak
>  alias.
>  
>  Alias that are not ``unnamed_addr`` are guaranteed to have the same address as
> -the aliasee.
> +the position represeted by the aliasee and offset.
> +
> +While it is valid for an offset to point outside of the aliasse, they
> +can only be use to compute pointers back into the object.
>  
>  The aliasee must be a definition.

I think you should explicitly state that the offset is in bytes.

> diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
> index 3282e8a..86ab6c4 100644
> --- a/lib/AsmParser/LLParser.cpp
> +++ b/lib/AsmParser/LLParser.cpp
> @@ -627,6 +627,29 @@ static bool isValidVisibilityForLinkage(unsigned V, unsigned L) {
>           (GlobalValue::VisibilityTypes)V == GlobalValue::DefaultVisibility;
>  }
>  
> +bool LLParser::parseInt64(int64_t &Offset) {
> +  if (Lex.getKind() != lltok::APSInt)
> +    return TokError("expected integer");
> +
> +  const APSInt &Val = Lex.getAPSIntVal();
> +  if (Val.getBitWidth() > 64)
> +    return TokError("expected a 64 bit unsegned integer");

s/unsegned/unsigned

> +
> +  if (Val.isSigned())
> +    Offset = Val.getSExtValue();
> +  else
> +    Offset = Val.getZExtValue();
> +  Lex.Lex();
> +  return false;
> +}
> +
> +bool LLParser::parseOptionalOffset(int64_t &Offset) {
> +  if (Lex.getKind() != lltok::kw_offset)
> +    return false;
> +  Lex.Lex();
> +  return parseInt64(Offset);
> +}
> +





More information about the llvm-commits mailing list