[PATCH] D69411: [MC] Calculate difference of symbols in two fragments when possible

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 02:31:49 PST 2019


peter.smith added a comment.

Thanks for the update. I'll wait a few days to see what comments we get. If there are none then I guess there aren't any strong objections.

To clarify the remarks about resolving .if at layout time. I think that there are two major obstacles.

- MC assembles instructions once, if the condition in the .if is not satisfied the contents of the block aren't even parsed. For example, the following will assemble if the .if condition fails, but will fail to parse if the .if condition passes. We'd need to change MC to either reparse (effectively making it a multipass assembler), or to parse and remember all parts. This is doable but it isn't a small change.

  .text
  .if 0
  You aren't parsing me are you?
  .else
  nop
  .endif

- The second problem, and not one unique to llvm-mc, is that it is possible to write a program that doesn't converge, something like (not testable as it needs relaxation and late evaluation of .if):

  label:
   beq after // In thumb 2 this 2-byte branch will be relaxed to a 4-byte branch if out of range. 
   .if . - label == 2 
   .space 1024 * 1024 // sufficient to make after out of range
   .endif
  after:
   nop

In pass 1, beq is 2-bytes in size, the .if passes, beq is then relaxed to 4-bytes, which would make the .if fail, which then makes beq 2-bytes ...
The interaction with relaxation could be fixed by making all size increases permanent. However I think it is possible to write multiple .if conditions that conflict. In Arm's old 2 - pass assembler (pass -1 find all sizes so layout is known, pass-2 encode instructions knowing layout), we had an error message when the equivalent of .if evaluated differently in subsequent passes. In summary, I think it would be a major change to MC to support something like late evaluation of .if in a reliable way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69411





More information about the llvm-commits mailing list