<div dir="ltr">Understood. Thank you for the explanation. But then maybe we should print out an error message if both --export-table and --import-table are specified. The way you are checking the presence of these flags are somewhat unusual which raised an alert when I was reading the code. I'll create a patch and send it to you.</div><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 28, 2018 at 2:02 PM Nicholas Wilson <<a href="mailto:nicholas@nicholaswilson.me.uk">nicholas@nicholaswilson.me.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Wasm's --import-table and --export-table are exclusive. That's because<br>
an imported table isn't defined in the Wasm file, so it doesn't make<br>
sense to export it.<br>
<br>
It's a tristate option: you don't have to either import or export<br>
(that is, doing neither is valid). So --no-import/export-table<br>
wouldn't really make sense as options (to me) since exporting it isn't<br>
the same as not importing it.<br>
<br>
I think it does make sense to have a positive option for<br>
--import-table and for --export-table, with the default being to<br>
neither import nor export it.<br>
<br>
There is choice of course of what to do if both --import-table and<br>
--export-table are specified; I opted to go with the last-defined, in<br>
the same that --foo and --no-foo override each other. I could make<br>
them produce an error if both are provided, if you think that's<br>
clearer.<br>
<br>
Thanks for the review.<br>
<br>
Nick<br>
<br>
On 28 March 2018 at 20:51, Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br>
> This is still odd. If Config->ImportTable and Config->ExportTable are<br>
> exclusive (and looks like they are), you should have only one boolean value.<br>
><br>
> Perhaps the flags are odd in the first place. Are --export-table and<br>
> --import-table exclusive? If so, why?<br>
><br>
> If something is exclusive, the standard way of representing it as a command<br>
> line flag is --foo and --no-foo, e.g. --rosegment and --no-rosegment.<br>
><br>
><br>
> On Wed, Mar 28, 2018 at 5:56 AM Nicholas Wilson via llvm-commits<br>
> <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
>><br>
>> Author: ncw<br>
>> Date: Wed Mar 28 05:53:29 2018<br>
>> New Revision: 328700<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=328700&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=328700&view=rev</a><br>
>> Log:<br>
>> [WebAssembly] Name Config members after commandline argument. NFC<br>
>><br>
>> This addresses a late review comment from D44427/rLLD328643<br>
>><br>
>> Modified:<br>
>>     lld/trunk/wasm/Config.h<br>
>>     lld/trunk/wasm/Driver.cpp<br>
>>     lld/trunk/wasm/Writer.cpp<br>
>><br>
>> Modified: lld/trunk/wasm/Config.h<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Config.h?rev=328700&r1=328699&r2=328700&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Config.h?rev=328700&r1=328699&r2=328700&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- lld/trunk/wasm/Config.h (original)<br>
>> +++ lld/trunk/wasm/Config.h Wed Mar 28 05:53:29 2018<br>
>> @@ -17,19 +17,18 @@<br>
>>  namespace lld {<br>
>>  namespace wasm {<br>
>><br>
>> -enum class ExposeAs { IMPORT, EXPORT, NONE };<br>
>> -<br>
>>  struct Configuration {<br>
>>    bool AllowUndefined;<br>
>>    bool CheckSignatures;<br>
>>    bool Demangle;<br>
>> +  bool ExportTable;<br>
>>    bool GcSections;<br>
>>    bool ImportMemory;<br>
>> +  bool ImportTable;<br>
>>    bool PrintGcSections;<br>
>>    bool Relocatable;<br>
>>    bool StripAll;<br>
>>    bool StripDebug;<br>
>> -  ExposeAs Table;<br>
>>    uint32_t GlobalBase;<br>
>>    uint32_t InitialMemory;<br>
>>    uint32_t MaxMemory;<br>
>><br>
>> Modified: lld/trunk/wasm/Driver.cpp<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=328700&r1=328699&r2=328700&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=328700&r1=328699&r2=328700&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- lld/trunk/wasm/Driver.cpp (original)<br>
>> +++ lld/trunk/wasm/Driver.cpp Wed Mar 28 05:53:29 2018<br>
>> @@ -216,15 +216,6 @@ static StringRef getEntry(opt::InputArgL<br>
>>    return Arg->getValue();<br>
>>  }<br>
>><br>
>> -static ExposeAs getExpose(opt::InputArgList &Args, unsigned Import,<br>
>> -                          unsigned Export) {<br>
>> -  auto *Arg = Args.getLastArg(Import, Export);<br>
>> -  if (!Arg)<br>
>> -    return ExposeAs::NONE;<br>
>> -  return Arg->getOption().getID() == Import ? ExposeAs::IMPORT<br>
>> -                                            : ExposeAs::EXPORT;<br>
>> -}<br>
>> -<br>
>>  static const uint8_t UnreachableFn[] = {<br>
>>      0x03 /* ULEB length */, 0x00 /* ULEB num locals */,<br>
>>      0x00 /* opcode unreachable */, 0x0b /* opcode end */<br>
>> @@ -305,7 +296,11 @@ void LinkerDriver::link(ArrayRef<const c<br>
>>    Config->SearchPaths = args::getStrings(Args, OPT_L);<br>
>>    Config->StripAll = Args.hasArg(OPT_strip_all);<br>
>>    Config->StripDebug = Args.hasArg(OPT_strip_debug);<br>
>> -  Config->Table = getExpose(Args, OPT_import_table, OPT_export_table);<br>
>> +  auto *TableArg = Args.getLastArg(OPT_import_table, OPT_export_table);<br>
>> +  Config->ImportTable =<br>
>> +      TableArg && TableArg->getOption().getID() == OPT_import_table;<br>
>> +  Config->ExportTable =<br>
>> +      TableArg && TableArg->getOption().getID() == OPT_export_table;<br>
>>    errorHandler().Verbose = Args.hasArg(OPT_verbose);<br>
>>    ThreadsEnabled = Args.hasFlag(OPT_threads, OPT_no_threads, true);<br>
>><br>
>><br>
>> Modified: lld/trunk/wasm/Writer.cpp<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=328700&r1=328699&r2=328700&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=328700&r1=328699&r2=328700&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- lld/trunk/wasm/Writer.cpp (original)<br>
>> +++ lld/trunk/wasm/Writer.cpp Wed Mar 28 05:53:29 2018<br>
>> @@ -127,7 +127,7 @@ void Writer::createImportSection() {<br>
>>    uint32_t NumImports = ImportedSymbols.size();<br>
>>    if (Config->ImportMemory)<br>
>>      ++NumImports;<br>
>> -  if (Config->Table == ExposeAs::IMPORT)<br>
>> +  if (Config->ImportTable)<br>
>>      ++NumImports;<br>
>><br>
>>    if (NumImports == 0)<br>
>> @@ -152,7 +152,7 @@ void Writer::createImportSection() {<br>
>>      writeImport(OS, Import);<br>
>>    }<br>
>><br>
>> -  if (Config->Table == ExposeAs::IMPORT) {<br>
>> +  if (Config->ImportTable) {<br>
>>      uint32_t TableSize = kInitialTableOffset + IndirectFunctions.size();<br>
>>      WasmImport Import;<br>
>>      Import.Module = "env";<br>
>> @@ -236,7 +236,7 @@ void Writer::createGlobalSection() {<br>
>>  }<br>
>><br>
>>  void Writer::createTableSection() {<br>
>> -  if (Config->Table == ExposeAs::IMPORT)<br>
>> +  if (Config->ImportTable)<br>
>>      return;<br>
>><br>
>>    // Always output a table section (or table import), even if there are<br>
>> no<br>
>> @@ -259,7 +259,7 @@ void Writer::createTableSection() {<br>
>><br>
>>  void Writer::createExportSection() {<br>
>>    bool ExportMemory = !Config->Relocatable && !Config->ImportMemory;<br>
>> -  bool ExportTable = !Config->Relocatable && Config->Table ==<br>
>> ExposeAs::EXPORT;<br>
>> +  bool ExportTable = !Config->Relocatable && Config->ExportTable;<br>
>><br>
>>    uint32_t NumExports =<br>
>>        (ExportMemory ? 1 : 0) + (ExportTable ? 1 : 0) +<br>
>> ExportedSymbols.size();<br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>