[llvm-bugs] [Bug 37836] New: Section address ignored when using MEMORY

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 18 06:22:19 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37836

            Bug ID: 37836
           Summary: Section address ignored when using MEMORY
           Product: lld
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: tdhutt at gmail.com
                CC: llvm-bugs at lists.llvm.org

Copy/paste from this SO question: https://stackoverflow.com/a/50910548/265521

I have a linker script:

    SECTIONS
    {
      .text 0x42000:
      {
        *(.text*)
      }

      aligned_dot = ALIGN(0x10 * 1024);  

      .data aligned_dot :
      {
        *(.data*)
      }
    }

If I link a (very simple) file using this it gives what I would expect:

    Sections:
    Idx Name          Size      Address          Type
      0               00000000 0000000000000000 
      1 .text         00000008 0000000000042000 TEXT DATA 
      2 .data         00000000 0000000000044000 TEXT BSS

And `aligned_dot` is:

    00044000 A aligned_dot

However, I'd like to use a `MEMORY` command like this:

    MEMORY
    {
      ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000
    }

    SECTIONS
    {
      .text :
      {
        *(.text*)
      }

      aligned_dot = ALIGN(0x10 * 1024);  

      .data aligned_dot :
      {
        *(.data*)
      }
    }

When I link using this script, it seems like the address of the `.data` section
is ignored!

    Sections:
    Idx Name          Size      Address          Type
      0               00000000 0000000000000000 
      1 .text         00000008 0000000000042000 TEXT DATA 
      2 .data         00000000 0000000000042008 TEXT BSS

Even though `aligned_dot` is still:

    00044000 A aligned_dot

I think this might be a bug in LLVM. In
[`LinkerScript.cpp`](https://github.com/llvm-mirror/lld/blob/master/ELF/LinkerScript.cpp#L762)
we have:

    void LinkerScript::assignOffsets(OutputSection *Sec) {
      if (!(Sec->Flags & SHF_ALLOC))
        Dot = 0;
      else if (Sec->AddrExpr)
        setDot(Sec->AddrExpr, Sec->Location, false);

      Ctx->MemRegion = Sec->MemRegion;
      Ctx->LMARegion = Sec->LMARegion;
      if (Ctx->MemRegion)
        Dot = Ctx->MemRegion->CurPos;

Which looks to me like it ignores the `AddrExpr` if `MemRegion` is set. If I
change the penultimate line to this then it works fine:

      if (Ctx->MemRegion && !Sec->AddrExpr)

Is this a bug?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180618/01976dc9/attachment.html>


More information about the llvm-bugs mailing list