Untested code

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 13 13:02:07 PDT 2016


On 13 April 2016 at 10:58, Simon Atanasyan <simon at atanasyan.com> wrote:
> On Wed, Apr 13, 2016 at 12:02 AM, Rafael EspĂ­ndola
> <rafael.espindola at gmail.com> wrote:
>> I think now there is only one if left untested (see the attached patch) :-)
>
> Attached patch adds test case and tries to fix the problem.
>
> _gp_disp designates offset between start of function and 'gp' pointer into GOT.
> Usually you can see the following code in the beginning of a function:
>
> lui    $t0, %hi(_gp_disp)
> addi   $t0, $t0, %lo(_gp_disp)
>
> When you calculate result of %hi(_gp_disp), you use %hi(_gp - P)
> expression. For the first instruction "_gp - P" gives the distance
> between the function and _gp. But for the second instruction you have
> to add four byte offset %hi(_gp - P + 4). Code in the trunk
> incorrectly calculates %lo(_gp_disp) as an absolute expression
> %lo(_gp).
>
> I am not sure that the fix is ideal. So I would appreciate any
> suggestions / objections.

Is it guaranteed that _gp_disp can only ever be used as the first two
instructions in a function? Is that restriction documented somewhere?
If so, please add a link to the documentation.

Instead of changing InputSection.cpp, can you put the +4  in the addend?

Cheers,
Rafael


More information about the llvm-commits mailing list