<div dir="ltr">Seems pretty plausible to me. </div><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 8, 2017 at 11:20 AM Robinson, Paul <<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In <a href="https://reviews.llvm.org/D30664" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D30664</a> Greg Clayton suggested adding a new<br class="gmail_msg">
version parameter to the macros that define DWARF constants (see<br class="gmail_msg">
include/Support/Dwarf.def).  This would enable various things:<br class="gmail_msg">
- a "verify" mode to dwarfdump that could warn about using features that<br class="gmail_msg">
  are newer than the stated version in a unit or other section;<br class="gmail_msg">
- a compiler assertion that guarded against using FORMs that are newer<br class="gmail_msg">
  than the requested version;<br class="gmail_msg">
- if we ever supported -gstrict-dwarf, a compiler assertion that we do<br class="gmail_msg">
  not emit any vendor extensions;<br class="gmail_msg">
- maybe other things.<br class="gmail_msg">
<br class="gmail_msg">
(Greg brought up "verify" mode, I am motivated by the FORM check.)<br class="gmail_msg">
<br class="gmail_msg">
It's easy enough (if tedious) to do the mechanical work to add a version<br class="gmail_msg">
to each constant, and some accessor functions to retrieve those values.<br class="gmail_msg">
The question is how to handle the vendor extensions.<br class="gmail_msg">
<br class="gmail_msg">
My thought was to define a fake version number for each "vendor" so we<br class="gmail_msg">
can easily identify them as nonstandard, and also identify which "vendor"<br class="gmail_msg">
defined a given extension.  Looking through Dwarf.def, the vendors are:<br class="gmail_msg">
MIPS, GNU, Apple, Borland, Google, LLVM.  DWARF does not define a "user"<br class="gmail_msg">
range for version numbers, but I should think it's safe enough to use<br class="gmail_msg">
values in the range 0xf0..0xff for this sort of thing.<br class="gmail_msg">
<br class="gmail_msg">
Class DwarfDebug already has a predicate to indicate it's okay to use<br class="gmail_msg">
Apple extensions, and tagging all Apple extensions with an Apple "version"<br class="gmail_msg">
would make it pretty trivial to add assertions in the emitter that this<br class="gmail_msg">
flag was obeyed.  For example.<br class="gmail_msg">
<br class="gmail_msg">
I would want to add a predicate to DwarfDebug that looked like this:<br class="gmail_msg">
<br class="gmail_msg">
  bool isValidFormForVersion(dwarf::Form Form) const {<br class="gmail_msg">
    unsigned FormVersion = dwarf::FormVersion(Form);<br class="gmail_msg">
    if (FormVersion <= getDwarfVersion())<br class="gmail_msg">
      return FormVersion != 0;<br class="gmail_msg">
    // The only extensions are GNU for split DWARF, pre-v5.<br class="gmail_msg">
    return (FormVersion == DWARF_VERSION_GNU && useSplitDwarf() &&<br class="gmail_msg">
            getDwarfVersion() <= 4);<br class="gmail_msg">
  }<br class="gmail_msg">
<br class="gmail_msg">
Then DIEAbbrev::Emit() could have an assertion along the lines of:<br class="gmail_msg">
  assert(AP->DD->isValidFormForVersion(Form) &&<br class="gmail_msg">
         "Form not defined in this DWARF version");<br class="gmail_msg">
<br class="gmail_msg">
Does this all seem like a reasonable direction?<br class="gmail_msg">
Thanks,<br class="gmail_msg">
--paulr<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div>