Skip to content

Commit

Permalink
[dev.cc] liblink: don't patch jumps to jumps to symbols
Browse files Browse the repository at this point in the history
When liblink sees something like

       JMP x
       ...
    x: JMP y

it rewrites the first jump to jump directly to y.  This is
fine if y is a resolved label.  However, it *also* does this
if y is a function symbol, but fails to carry over the
relocation that would later patch in that symbol's value.  As
a result, the original jump becomes either a self-jump (if
relative) or a jump to PC 0 (if absolute).

Fix this by disabling this optimization if the jump being
patched in is a jump to a symbol.

LGTM=minux
R=rsc, minux
CC=golang-codereviews
https://golang.org/cl/185890044
  • Loading branch information
aclements committed Dec 5, 2014
1 parent 274976f commit e04c8b0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/liblink/pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ brchain(Link *ctxt, Prog *p)
int i;

for(i=0; i<20; i++) {
if(p == nil || p->as != ctxt->arch->AJMP)
if(p == nil || p->as != ctxt->arch->AJMP || p->pcond == nil)
return p;
p = p->pcond;
}
Expand All @@ -56,7 +56,7 @@ brloop(Link *ctxt, Prog *p)

c = 0;
for(q = p; q != nil; q = q->pcond) {
if(q->as != ctxt->arch->AJMP)
if(q->as != ctxt->arch->AJMP || q->pcond == nil)
break;
c++;
if(c >= 5000)
Expand Down

0 comments on commit e04c8b0

Please sign in to comment.