On Tue, Jun 23, 2020 at 07:28:06AM -0400, Neil Horman wrote:
> On Mon, Jun 22, 2020 at 10:39:46PM +0300, Dmitry Kozlyuk wrote:
> > On Mon, 22 Jun 2020 08:41:17 -0400, Neil Horman wrote:
> > > On Mon, Jun 22, 2020 at 03:45:01AM +0300, Dmitry Kozlyuk wrote:
> > [snip]

> > 
> > > > 2. How much error-handling is required? This is a build-time tool,
> > > >     and Python gives nice stacktraces. However, segfaults are possible
> > > >     in Python version due to pointer handling. IMO, error checking
> > > >     must be just sufficient to prevent silent segfaults.
> > > >   
> > > I'm not really sure what the question is here.  You need to handle errors 
> > > in the
> > > parsing process, we can't just have the tool crashing during the build.  
> > > How
> > > thats handled is an implementation detail I would think.
> > 
> > Consider a snippet from pmdinfogen.c:
> > 
> >     /* Check if file offset is correct */
> >     if (hdr->e_shoff > info->size) {
> >             fprintf(stderr, "section header offset=%lu in file '%s' "
> >                   "is bigger than filesize=%lu\n",
> >                   (unsigned long)hdr->e_shoff,
> >                   filename, info->size);
> >             return 0;
> >     }
> > 
> > It is required in C, because otherwise pmdinfogen would crash without
> > diagnostic. With Python, most errors like this result in a crash with a 
> > trace
> > to the error line and a message from ctypes (or ELF parsing library). I'm
> > arguing for leaving only the checks that prevent *silent* crashes (this can
> > happen with ctypes) which are hard to diagnose. Motivation is to keep the
> > code simple.
> > 
> Hmm, I'd defer to others opinions on that.  As a build tool it may be ok to 
> just
> crash with a backtrace, but I'm personally not a fan of that.  Id rather see a
> diagnostic error and have the tool exits with an appropriate exit code, but 
> lets
> see what others say.
>
I'd take a wait-and-see approach here. Obviously individualized errors
messages are better, but for a case like the above where we have a
malformed elf header, I would think that this is such a rare event that
just letting python exception handling manage it should be ok.
 
> > 
> > > > 3. On Unix, pmdinfogen is called for each object file extracted with ar
> > > >     from an .a library by a shell script. On Windows, other tools
> > > >     have to be used, shell script will not work. On the other hand, COFF
> > > >     library format is quite simple. Would it be appropriate for
> > > >     pmdinfogen to handle it to avoid intermediate script?
> > > >   
> > > I suppose you could, but extracting objects from archives seems outside 
> > > the
> > > scope of what pmdinfogen normally does.  What is the problem with using a 
> > > shell
> > > script on windows?  I thought WSL had support for executing bash syntax 
> > > shell
> > > scripts there?  Why not key off an environment variable to make the 
> > > relevant
> > > scripts do the right thing on your environment?
> > 
> > WSL2 is a Linux VM integrated in Windows, you can only cross-compile from
> > there. Native builds can use Python or PowerShell, which is as capable as 
> > Unix
> > shells, but incompatible with them. To call lib.exe (MSVC analog of ar) is
> > probably simpler then parsing COFF, yes. So meson could select one of the
> > following for a Windows target (objects are COFF):
> > 
> > Host     Toolchain  Archive  Script      Extractor
> > -------  ---------  -------  ---------   ---------
> > Linux    MinGW      .a       sh          ar
> > Windows  MinGW      .a       PowerShell  ar
> > Windows  Clang      .lib     PowerShell  lib
> I think if I read you right, what you're suggesting here is that meson setup a
> build time marco $ARCHIVETOOL, and set it to ar or lib.exe depending on the
> build environment, and just have the script in question use $ARCHIVER?  If so,
> I'd be good with that.  Do we have to worry about the use of divergent command
> line options for each tool as well?
> 
It might be better just to do that detection in the python script itself,
rather than in meson, since the script may have to do other behavioural
changes based on the platform.

Regards,
/Bruce

Reply via email to