[PATCH] D79926: [lld-macho] Support .subsections_via_symbols

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 18 20:36:45 PDT 2020


int3 marked an inline comment as done.
int3 added inline comments.


================
Comment at: lld/MachO/InputFiles.cpp:278
+    firstIsec->data = firstIsec->data.slice(0, firstSize);
+    secondIsec->align = MinAlign(firstIsec->align, offset);
+
----------------
smeenai wrote:
> int3 wrote:
> > smeenai wrote:
> > > What's the reason for this?
> > The symbol we're splitting on may not be at an aligned offset from the first input section. E.g. we may have a section `__text` aligned to 0x8 and a symbol offset 0x4 from the start of `__text`.
> Hmm. I guess choosing the minimum makes sense in that case? I'd be curious if ld64 does that or just preserves the alignment of the original section (and aligns the subsection accordingly).
Good point, I hadn't actually checked what ld64 was doing -- the present minalign behavior was from @pcc's original implementation (with some tweaking).

Some testing suggests that what ld64 is doing is preserving the alignment of the original section, plus adding an offset for each subsection to preserve how far away it is from an aligned address. This is the file I was playing around with to observe this behavior:

```
.globl _main
.p2align 4
.text
_foo:
  .space 2
_bar:
  .space 1
_baz:

_main:
  ret

.subsections_via_symbols
```

linked with the order file

```
_baz
_bar
_foo
```

_bar ends up at an aligned address + 2, and baz at another aligned address + 3.

I think I'd like to punt on emulating this for now, but I'll add a TODO.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79926/new/

https://reviews.llvm.org/D79926





More information about the llvm-commits mailing list