[PATCH] D41459: [lld] Fix output section offset and contents when linker script uses memory region and data commands

Owen Shaw via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 18:02:58 PST 2017


I do not have commit access.

Thanks,
Owen

On Fri, Dec 22, 2017 at 8:58 AM, Rafael Avila de Espindola <
rafael.espindola at gmail.com> wrote:

> LGTM.
>
> Do you have commit access?
>
> Thanks,
> Rafael
>
> Owen Shaw via Phabricator via llvm-commits <llvm-commits at lists.llvm.org>
> writes:
>
> > owenpshaw updated this revision to Diff 127910.
> > owenpshaw removed a reviewer: lld.
> > owenpshaw added a comment.
> >
> > Thanks for the help!
> >
> > Updated the patch with suggested changes to braces.
> >
> >
> > https://reviews.llvm.org/D41459
> >
> > Files:
> >   ELF/LinkerScript.cpp
> >   test/ELF/linkerscript/data-commands.s
> >
> >
> > Index: test/ELF/linkerscript/data-commands.s
> > ===================================================================
> > --- test/ELF/linkerscript/data-commands.s
> > +++ test/ELF/linkerscript/data-commands.s
> > @@ -44,6 +44,42 @@
> >  # BE-NEXT:   ff12ff11 22ff1122 3346ff11 22334455
> >  # BE-NEXT:   667788
> >
> > +# RUN: echo "MEMORY {                \
> > +# RUN:     rom (rwx) : ORIGIN = 0x00, LENGTH = 2K \
> > +# RUN:  }                            \
> > +# RUN:  SECTIONS {                   \
> > +# RUN:    .foo : {                   \
> > +# RUN:      *(.foo.1)                \
> > +# RUN:      BYTE(0x11)               \
> > +# RUN:      *(.foo.2)                \
> > +# RUN:      SHORT(0x1122)            \
> > +# RUN:      *(.foo.3)                \
> > +# RUN:      LONG(0x11223344)         \
> > +# RUN:      *(.foo.4)                \
> > +# RUN:      QUAD(0x1122334455667788) \
> > +# RUN:    } > rom                    \
> > +# RUN:    .bar : {                   \
> > +# RUN:      *(.bar.1)                \
> > +# RUN:      BYTE(a + 1)              \
> > +# RUN:      *(.bar.2)                \
> > +# RUN:      SHORT(b)                 \
> > +# RUN:      *(.bar.3)                \
> > +# RUN:      LONG(c + 2)              \
> > +# RUN:      *(.bar.4)                \
> > +# RUN:      QUAD(d)                  \
> > +# RUN:    } > rom                    \
> > +# RUN:  }" > %t-memory.script
> > +# RUN: ld.lld -o %t-memory %t.o --script %t-memory.script
> > +# RUN: llvm-objdump -s %t-memory | FileCheck %s --check-prefix=MEM
> > +
> > +# MEM:      Contents of section .foo:
> > +# MEM-NEXT:   0000 ff11ff22 11ff4433 2211ff88 77665544
> > +# MEM-NEXT:   0010 332211
> > +
> > +# MEM:      Contents of section .bar:
> > +# MEM-NEXT:   0013 ff12ff22 11ff4633 2211ff88 77665544
> > +# MEM-NEXT:   0023 332211
> > +
> >  .global a
> >  a = 0x11
> >
> > Index: ELF/LinkerScript.cpp
> > ===================================================================
> > --- ELF/LinkerScript.cpp
> > +++ ELF/LinkerScript.cpp
> > @@ -693,6 +693,8 @@
> >      if (auto *Cmd = dyn_cast<ByteCommand>(Base)) {
> >        Cmd->Offset = Dot - Ctx->OutSec->Addr;
> >        Dot += Cmd->Size;
> > +      if (Ctx->MemRegion)
> > +        Ctx->MemRegionOffset[Ctx->MemRegion] += Cmd->Size;
> >        Ctx->OutSec->Size = Dot - Ctx->OutSec->Addr;
> >        continue;
> >      }
> >
> >
> > Index: test/ELF/linkerscript/data-commands.s
> > ===================================================================
> > --- test/ELF/linkerscript/data-commands.s
> > +++ test/ELF/linkerscript/data-commands.s
> > @@ -44,6 +44,42 @@
> >  # BE-NEXT:   ff12ff11 22ff1122 3346ff11 22334455
> >  # BE-NEXT:   667788
> >
> > +# RUN: echo "MEMORY {                \
> > +# RUN:     rom (rwx) : ORIGIN = 0x00, LENGTH = 2K \
> > +# RUN:  }                            \
> > +# RUN:  SECTIONS {                   \
> > +# RUN:    .foo : {                   \
> > +# RUN:      *(.foo.1)                \
> > +# RUN:      BYTE(0x11)               \
> > +# RUN:      *(.foo.2)                \
> > +# RUN:      SHORT(0x1122)            \
> > +# RUN:      *(.foo.3)                \
> > +# RUN:      LONG(0x11223344)         \
> > +# RUN:      *(.foo.4)                \
> > +# RUN:      QUAD(0x1122334455667788) \
> > +# RUN:    } > rom                    \
> > +# RUN:    .bar : {                   \
> > +# RUN:      *(.bar.1)                \
> > +# RUN:      BYTE(a + 1)              \
> > +# RUN:      *(.bar.2)                \
> > +# RUN:      SHORT(b)                 \
> > +# RUN:      *(.bar.3)                \
> > +# RUN:      LONG(c + 2)              \
> > +# RUN:      *(.bar.4)                \
> > +# RUN:      QUAD(d)                  \
> > +# RUN:    } > rom                    \
> > +# RUN:  }" > %t-memory.script
> > +# RUN: ld.lld -o %t-memory %t.o --script %t-memory.script
> > +# RUN: llvm-objdump -s %t-memory | FileCheck %s --check-prefix=MEM
> > +
> > +# MEM:      Contents of section .foo:
> > +# MEM-NEXT:   0000 ff11ff22 11ff4433 2211ff88 77665544
> > +# MEM-NEXT:   0010 332211
> > +
> > +# MEM:      Contents of section .bar:
> > +# MEM-NEXT:   0013 ff12ff22 11ff4633 2211ff88 77665544
> > +# MEM-NEXT:   0023 332211
> > +
> >  .global a
> >  a = 0x11
> >
> > Index: ELF/LinkerScript.cpp
> > ===================================================================
> > --- ELF/LinkerScript.cpp
> > +++ ELF/LinkerScript.cpp
> > @@ -693,6 +693,8 @@
> >      if (auto *Cmd = dyn_cast<ByteCommand>(Base)) {
> >        Cmd->Offset = Dot - Ctx->OutSec->Addr;
> >        Dot += Cmd->Size;
> > +      if (Ctx->MemRegion)
> > +        Ctx->MemRegionOffset[Ctx->MemRegion] += Cmd->Size;
> >        Ctx->OutSec->Size = Dot - Ctx->OutSec->Addr;
> >        continue;
> >      }
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171222/64f39f27/attachment.html>


More information about the llvm-commits mailing list