|
|
Descriptioncmd/ld: abort if (32-bit) address relocation is negative on amd64.
Update issue 7980
This CL make the linker abort for the example program. For Go 1.4,
we need to find a general way to handle large memory model programs.
Patch Set 1 #Patch Set 2 : diff -r 3458ba248590 https://code.google.com/p/go #Patch Set 3 : diff -r 3458ba248590 https://code.google.com/p/go #
Total comments: 2
Patch Set 4 : diff -r 43fdb7e80241 https://code.google.com/p/go #Patch Set 5 : diff -r 43fdb7e80241 https://code.google.com/p/go #MessagesTotal messages: 12
Hello iant@golang.org (cc: golang-codereviews@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
Sign in to reply to this message.
LGTM. I think this is a reasonable way to ensure we don't generate broken programs. As I understand it there is an existing problem with the compier/linker that if I say package p var a [1<<24]int This is already not handled efficiently by the compiler/linker, so the problem we are protecting against is not the common (I hope) On Fri, May 16, 2014 at 9:20 AM, <minux.ma@gmail.com> wrote: > Reviewers: iant, > > Message: > Hello iant@golang.org (cc: golang-codereviews@googlegroups.com), > > I'd like you to review this change to > https://code.google.com/p/go > > > Description: > cmd/ld: abort if (32-bit) address relocation is negative on amd64. > Update issue 7980 > This CL make the linker abort for the example program. For Go 1.4, > we need to find a general way to handle large memory model programs. > > Please review this at https://codereview.appspot.com/91500046/ > > Affected files (+6, -0 lines): > M src/cmd/ld/data.c > > > Index: src/cmd/ld/data.c > =================================================================== > --- a/src/cmd/ld/data.c > +++ b/src/cmd/ld/data.c > @@ -243,6 +243,12 @@ > break; > } > o = symaddr(r->sym) + r->add; > + > + // On amd64, offset will be sign-extended, so it is > impossible to access > + // more than 2GB of static data; fail at link time > is better than fail at > + // runtime. See http://golang.org/issue/7980. > + if((int32)o < 0 && thechar == '6') > + diag("non-pc-relative relocation address is > too big: %#llux", o); > break; > case R_CALL: > case R_PCREL: > > > -- > You received this message because you are subscribed to the Google Groups > "golang-codereviews" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-codereviews+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/d/optout.
Sign in to reply to this message.
LGTM, at least for 1.3 Thanks, minux. https://codereview.appspot.com/91500046/diff/40001/src/cmd/ld/data.c File src/cmd/ld/data.c (right): https://codereview.appspot.com/91500046/diff/40001/src/cmd/ld/data.c#newcode251 src/cmd/ld/data.c:251: diag("non-pc-relative relocation address is too big: %#llux", o); Add errorexit() -- once this happens, there's no point in continuing.
Sign in to reply to this message.
https://codereview.appspot.com/91500046/diff/40001/src/cmd/ld/data.c File src/cmd/ld/data.c (right): https://codereview.appspot.com/91500046/diff/40001/src/cmd/ld/data.c#newcode250 src/cmd/ld/data.c:250: if((int32)o < 0 && thechar == '6') I think we can future-proof this a bit. if(siz == 4 && PtrSize > 4 && (int32)o < 0)
Sign in to reply to this message.
Hello iant@golang.org, dave@cheney.net, josharian@gmail.com (cc: golang-codereviews@googlegroups.com), Please take another look.
Sign in to reply to this message.
On May 15, 2014 7:53 PM, <josharian@gmail.com> wrote: > https://codereview.appspot.com/91500046/diff/40001/src/cmd/ld/data.c > File src/cmd/ld/data.c (right): > > https://codereview.appspot.com/91500046/diff/40001/src/cmd/ld/data.c#newcode251 > src/cmd/ld/data.c:251: diag("non-pc-relative relocation address is too > big: %#llux", o); > Add errorexit() -- once this happens, there's no point in continuing. yes, and this error most likely will lead to cascaded errors so better exit now.
Sign in to reply to this message.
> src/cmd/ld/data.c:250: if((int32)o < 0 && thechar == '6') > I think we can future-proof this a bit. > > if(siz == 4 && PtrSize > 4 && (int32)o < 0) Maybe I'm missing something, but the use of signed pointers seems architecture-specific, so checking explicitly for amd64 seems right here. Perhaps we could future-proof by adding a diagnostic test instead. It's not clear to me what that should look like, though, given that we're punting for now.
Sign in to reply to this message.
On May 15, 2014 7:53 PM, <iant@golang.org> wrote: > https://codereview.appspot.com/91500046/diff/40001/src/cmd/ld/data.c > File src/cmd/ld/data.c (right): > > https://codereview.appspot.com/91500046/diff/40001/src/cmd/ld/data.c#newcode250 > src/cmd/ld/data.c:250: if((int32)o < 0 && thechar == '6') > I think we can future-proof this a bit. > > if(siz == 4 && PtrSize > 4 && (int32)o < 0) adopted. although i think it's fairly certain that all 64-bit architectures will sign-extend a offset, this probably won't work on aarch64 (as the addend contains the actual instruction). however we need a better way to handle that case anyway.
Sign in to reply to this message.
On Thu, May 15, 2014 at 5:08 PM, <josharian@gmail.com> wrote: >> src/cmd/ld/data.c:250: if((int32)o < 0 && thechar == '6') >> I think we can future-proof this a bit. > > >> if(siz == 4 && PtrSize > 4 && (int32)o < 0) > > > Maybe I'm missing something, but the use of signed pointers seems > architecture-specific, so checking explicitly for amd64 seems right > here. Each new 64-bit architecture with 32-bit relocs will need this condition checked and handled as appropriate. Just checking for amd64 as in the original patch means that other architectures may silently accept a bad reloc. We could add a switch and crash on an unknown case but that seems like overkill at present. It seems OK to me to leave this as I wrote it and then modify it if we later find that we need to. Ian
Sign in to reply to this message.
LGTM
Sign in to reply to this message.
> >> src/cmd/ld/data.c:250: if((int32)o < 0 && thechar == '6') > >> I think we can future-proof this a bit. > > > > > >> if(siz == 4 && PtrSize > 4 && (int32)o < 0) > > > > > > Maybe I'm missing something, but the use of signed pointers seems > > architecture-specific, so checking explicitly for amd64 seems right > > here. > > Each new 64-bit architecture with 32-bit relocs will need this > condition checked and handled as appropriate. Just checking for amd64 > as in the original patch means that other architectures may silently > accept a bad reloc. We could add a switch and crash on an unknown > case but that seems like overkill at present. It seems OK to me to > leave this as I wrote it and then modify it if we later find that we > need to. Ahhh. Makes sense; thanks for the explanation.
Sign in to reply to this message.
*** Submitted as https://code.google.com/p/go/source/detail?r=793272b5aeef *** cmd/ld: abort if (32-bit) address relocation is negative on amd64. Update issue 7980 This CL make the linker abort for the example program. For Go 1.4, we need to find a general way to handle large memory model programs. LGTM=dave, josharian, iant R=iant, dave, josharian CC=golang-codereviews https://codereview.appspot.com/91500046 Committer: Russ Cox <rsc@golang.org>
Sign in to reply to this message.
|
