[PATCH] D72899: [MC] Set sh_link to 0 if the associated symbol is undefined

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 13:56:26 PST 2020


pcc added a comment.

> 2. Add a non-GC-root dummy section. This is a bit awkward to implement in MC because we have to pick a section name. The section may be combined with other normal sections with the same name. We need to be careful and not cause an "incompatible section flags" error (lld specific).

For this you could use .text or something else relatively common with well known flag values. We could do this in other cases where the section is known to be GCable (i.e. not !associated). But I don't think we should do this for !associated because:

> 3. Add a GC-root dummy section, for example, SHT_INIT_ARRAY, and name it .init_array, so that it can be comined with other .init_array sections. Note other sh_link!=0 sections can be garbage collected.
> 
>   I want to avoid 3 because it causes a behavior difference.

We use the !associated metadata to mean that the global *may* be discarded when the referenced global is discarded, not that it *must* be discarded in that case. If the referenced global pointer is null, it could mean that an optimization pass has combined multiple globals (see e.g. GlobalMerge pass) and not updated the metadata. This is valid for a pass to do since passes are not required to update metadata. For example:

  @a = global i32 1
  @b = global i32 2
  @c = global i32 3, section "foo", !associated @a
  @d = global i32 4, section "foo", !associated @b

becomes

  @ab = global {i32 1, i32 2}
  @c = global i32 3, section "foo", !associated gep(@a, 0, 0) ; could become !associated null as a result of discarding unused ConstantExprs
  @d = global i32 4, section "foo", !associated gep(@a, 0, 1) ; ditto

In this case we should keep `@c` and `@d` despite associated metadata potentially being null, because `@ab` may still be alive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72899





More information about the llvm-commits mailing list