[PATCH] Add a jumptable attribute and support for creating jump-instruction tables

Tom Roeder tmroeder at google.com
Wed May 21 11:47:00 PDT 2014


On Tue, May 20, 2014 at 7:20 PM, Rafael EspĂ­ndola
<rafael.espindola at gmail.com> wrote:
>>> Also, as I was working on these fixes, I found a problem with GlobalAlias:
>>> it doesn't support replaceUsesOfWithOnConstant, and it cannot target
>>> declaration-only functions. So, I've added some special-case handling for
>>> GlobalAlias statements that target jumptable functions. I've also added a
>>> new test case for "alias".
>>
>>
>> Rafael, could you take a look at how this interacts with global aliases?
>>
>
> So, parachuting down the middle of the code review. Apologies if I
> misunderstand something.
>
> Alias to declarations are not allowed because there is no way to
> represent them in the object files. Once we get to assembly an alias
> is just another name for a "position" in the file, not a linker
> directive, so it can only point to something that exists in the file.
>
> How are you hitting aliases to undefined? My understanding from
> browsing the changes to LangRef is that any function with the
> jumptable attribute gets replaced with a position in a table and that
> position is always a definition, no?

Not quite. The jumptable code creates a declaration (but not a
definition) that will later be satisfied by generated assembly in
AsmPrinter. It then goes and replaces all address-taken uses of the
function symbol with the declaration. So, the problem happens when
there's a statement like

@falias = alias i32 ()* @f

where @f has the jumptable attribute and is being replaced with a
declared but not defined function, say @f_JT. Ideally, I'd just be
able to replace @f with @f_JT, but since there's no definition for
@f_JT, the GlobalAlias code balks, for good reasons, as you explained.

It happens that this declaration in this case is going to resolve into
a real symbol in the same asm file, but there's no way the code can
tell that.

So, instead, part of my pass looks for GlobalAliases to find ones that
need to be treated in the same way as the jumptable functions they
alias. I don't have a problem with adding this little bit of extra
code to handle aliases correctly, but I'm happy to change it if
there's a better way to do it.

>
> When you say that replaceUsesOfWithOnConstant doesn't work with
> aliases you mean that you cannot pass an alias as the From argument?
> That should be just an oversight, I don't think there is any
> fundamental reason why that would not work. What is the issues that
> you are seeing?

No, that case works fine, and I do it extensively in this version of
the code; that's how I replace the GlobalAliases to jumptable
Functions that I find. The thing that doesn't work is calling

C->replaceUsesOfWithOnConstant(GV, V, U)

when C is a GlobalAlias. I've just looked at the code, though, and it
looks like this is a red herring: you can replace alias targets with
other calls, so it doesn't matter. In the end, the thing that prevents
me from making this replacement is having the replacement function be
a declaration and not a defined function.




More information about the llvm-commits mailing list