<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Section address ignored when using MEMORY"
   href="https://bugs.llvm.org/show_bug.cgi?id=37836">37836</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Section address ignored when using MEMORY
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tdhutt@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Copy/paste from this SO question: <a href="https://stackoverflow.com/a/50910548/265521">https://stackoverflow.com/a/50910548/265521</a>

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`](<a href="https://github.com/llvm-mirror/lld/blob/master/ELF/LinkerScript.cpp#L762">https://github.com/llvm-mirror/lld/blob/master/ELF/LinkerScript.cpp#L762</a>)
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?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>