diff mbox

Fix intelmic-mkoffload.c if the temp path contains a '-'

Message ID D7EFF377C0894A47B63545C223A166A531B9B1D4@MBX-S2.rwth-ad.de
State New
Headers show

Commit Message

Hahnfeld, Jonas Sept. 1, 2015, 11:35 a.m. UTC
Hopefully CC'ing the right people...

> -----Original Message-----
> From: Hahnfeld, Jonas
> Sent: Thursday, August 20, 2015 12:25 PM
> To: 'gcc-patches@gcc.gnu.org'
> Subject: Fix intelmic-mkoffload.c if the temp path contains a '-'
> 
> Hi all,
> 
> during my test of OpenMP 4.0 offloading features I have found a bug in
> intelmic-mkoffload.c when the temp path contains a '-'.
> objcopy will in this case replace it with a '_' which wasn't reflected in
> the original code and resulted in a link error of the symbols
> '__offload_image_intelmic_start' and '__offload_image_intelmic_end'.
> 
> This is my first contribution, so just reply if anything is wrong and I'll
> happily fix it.
> 
> Greetings,
> Jonas
> 
> --
> Jonas Hahnfeld, MATSE-Auszubildender
> 
> IT Center
> Group: High Performance Computing
> Division: Computational Science and Engineering
> RWTH Aachen University
> Seffenter Weg 23
> D 52074  Aachen (Germany)
> Hahnfeld@itc.rwth-aachen.de
> www.itc.rwth-aachen.de

From git-format-patch:

From 884b6199179e7a604474bc6a828a6861d3ff4501 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <Hahnfeld@itc.rwth-aachen.de>
Date: Thu, 20 Aug 2015 12:13:55 +0200
Subject: [PATCH] Fix intelmic-mkoffload.c if the temp path contains a '-'

2015-08-20  Jonas Hahnfeld  <Hahnfeld@itc.rwth-aachen.de>

	* intelmic-mkoffload.c (prepare_target_image): Fix if the temp path
	contains a '-'.
---
 gcc/config/i386/intelmic-mkoffload.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

     }

Comments

Ilya Verbin Sept. 1, 2015, 11:46 a.m. UTC | #1
On Tue, Sep 01, 2015 at 11:35:15 +0000, Hahnfeld, Jonas wrote:
> > during my test of OpenMP 4.0 offloading features I have found a bug in
> > intelmic-mkoffload.c when the temp path contains a '-'.
> > objcopy will in this case replace it with a '_' which wasn't reflected in
> > the original code and resulted in a link error of the symbols
> > '__offload_image_intelmic_start' and '__offload_image_intelmic_end'.
> > 
> > This is my first contribution, so just reply if anything is wrong and I'll
> > happily fix it.

Thanks!  Please wait for Jakub's approval before checking-in.

  -- Ilya
Jakub Jelinek Sept. 1, 2015, 11:50 a.m. UTC | #2
On Tue, Sep 01, 2015 at 11:35:15AM +0000, Hahnfeld, Jonas wrote:
> >From 884b6199179e7a604474bc6a828a6861d3ff4501 Mon Sep 17 00:00:00 2001
> From: Jonas Hahnfeld <Hahnfeld@itc.rwth-aachen.de>
> Date: Thu, 20 Aug 2015 12:13:55 +0200
> Subject: [PATCH] Fix intelmic-mkoffload.c if the temp path contains a '-'
> 
> 2015-08-20  Jonas Hahnfeld  <Hahnfeld@itc.rwth-aachen.de>
> 
> 	* intelmic-mkoffload.c (prepare_target_image): Fix if the temp path
> 	contains a '-'.
> ---
>  gcc/config/i386/intelmic-mkoffload.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/gcc/config/i386/intelmic-mkoffload.c
> b/gcc/config/i386/intelmic-mkoffload.c
> index ca15868..c9327cf 100644
> --- a/gcc/config/i386/intelmic-mkoffload.c
> +++ b/gcc/config/i386/intelmic-mkoffload.c
> @@ -460,7 +460,7 @@ prepare_target_image (const char *target_compiler, int
> argc, char **argv)
>    for (size_t i = 0; i <= symbol_name_len; i++)
>      {
>        char c = target_so_filename[i];
> -      if ((c == '/') || (c == '.'))
> +      if ((c == '/') || (c == '.') || (c == '-'))

The ()s around the comparisons are unnecessary, but it is preexisting,
so the fix is ok for trunk with or without the removal of those ()s.

	Jakub
Hahnfeld, Jonas Sept. 1, 2015, 11:53 a.m. UTC | #3
> -----Original Message-----
> From: Jakub Jelinek [mailto:jakub@redhat.com]
> Sent: Tuesday, September 01, 2015 1:50 PM
> To: Hahnfeld, Jonas
> Cc: gcc-patches@gcc.gnu.org; Ilya Verbin; Kirill Yukhin
> Subject: Re: Fix intelmic-mkoffload.c if the temp path contains a '-'
> 
> On Tue, Sep 01, 2015 at 11:35:15AM +0000, Hahnfeld, Jonas wrote:
> > >From 884b6199179e7a604474bc6a828a6861d3ff4501 Mon Sep 17 00:00:00
> > >2001
> > From: Jonas Hahnfeld <Hahnfeld@itc.rwth-aachen.de>
> > Date: Thu, 20 Aug 2015 12:13:55 +0200
> > Subject: [PATCH] Fix intelmic-mkoffload.c if the temp path contains a
'-'
> >
> > 2015-08-20  Jonas Hahnfeld  <Hahnfeld@itc.rwth-aachen.de>
> >
> > 	* intelmic-mkoffload.c (prepare_target_image): Fix if the temp path
> > 	contains a '-'.
> > ---
> >  gcc/config/i386/intelmic-mkoffload.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/gcc/config/i386/intelmic-mkoffload.c
> > b/gcc/config/i386/intelmic-mkoffload.c
> > index ca15868..c9327cf 100644
> > --- a/gcc/config/i386/intelmic-mkoffload.c
> > +++ b/gcc/config/i386/intelmic-mkoffload.c
> > @@ -460,7 +460,7 @@ prepare_target_image (const char
> *target_compiler,
> > int argc, char **argv)
> >    for (size_t i = 0; i <= symbol_name_len; i++)
> >      {
> >        char c = target_so_filename[i];
> > -      if ((c == '/') || (c == '.'))
> > +      if ((c == '/') || (c == '.') || (c == '-'))
> 
> The ()s around the comparisons are unnecessary, but it is preexisting, so
the
> fix is ok for trunk with or without the removal of those ()s.
> 
> 	Jakub

Could you commit the patch for me as I don't have commit access?
And also consider backporting this trivial fix for 'gcc-5-branch'?

Thanks,
Jonas
Hahnfeld, Jonas Sept. 4, 2015, 11:10 a.m. UTC | #4
> -----Original Message-----
> From: Hahnfeld, Jonas
> Sent: Tuesday, September 01, 2015 1:54 PM
> To: 'Jakub Jelinek'
> Cc: gcc-patches@gcc.gnu.org; Ilya Verbin; Kirill Yukhin
> Subject: RE: Fix intelmic-mkoffload.c if the temp path contains a '-'
> 
> > -----Original Message-----
> > From: Jakub Jelinek [mailto:jakub@redhat.com]
> > Sent: Tuesday, September 01, 2015 1:50 PM
> > To: Hahnfeld, Jonas
> > Cc: gcc-patches@gcc.gnu.org; Ilya Verbin; Kirill Yukhin
> > Subject: Re: Fix intelmic-mkoffload.c if the temp path contains a '-'
> >
> > On Tue, Sep 01, 2015 at 11:35:15AM +0000, Hahnfeld, Jonas wrote:
> > > >From 884b6199179e7a604474bc6a828a6861d3ff4501 Mon Sep 17
> 00:00:00
> > > >2001
> > > From: Jonas Hahnfeld <Hahnfeld@itc.rwth-aachen.de>
> > > Date: Thu, 20 Aug 2015 12:13:55 +0200
> > > Subject: [PATCH] Fix intelmic-mkoffload.c if the temp path contains a
> '-'
> > >
> > > 2015-08-20  Jonas Hahnfeld  <Hahnfeld@itc.rwth-aachen.de>
> > >
> > > 	* intelmic-mkoffload.c (prepare_target_image): Fix if the temp path
> > > 	contains a '-'.
> > > ---
> > >  gcc/config/i386/intelmic-mkoffload.c |    2 +-
> > >  1 files changed, 1 insertions(+), 1 deletions(-)
> > >
> > > diff --git a/gcc/config/i386/intelmic-mkoffload.c
> > > b/gcc/config/i386/intelmic-mkoffload.c
> > > index ca15868..c9327cf 100644
> > > --- a/gcc/config/i386/intelmic-mkoffload.c
> > > +++ b/gcc/config/i386/intelmic-mkoffload.c
> > > @@ -460,7 +460,7 @@ prepare_target_image (const char
> > *target_compiler,
> > > int argc, char **argv)
> > >    for (size_t i = 0; i <= symbol_name_len; i++)
> > >      {
> > >        char c = target_so_filename[i];
> > > -      if ((c == '/') || (c == '.'))
> > > +      if ((c == '/') || (c == '.') || (c == '-'))
> >
> > The ()s around the comparisons are unnecessary, but it is preexisting,
so
> the
> > fix is ok for trunk with or without the removal of those ()s.
> >
> > 	Jakub
> 
> Could you commit the patch for me as I don't have commit access?
> And also consider backporting this trivial fix for 'gcc-5-branch'?
> 
> Thanks,
> Jonas

*ping*
I don't have write access to the repository...

Thanks,
Jonas
Ilya Verbin Sept. 4, 2015, 11:23 a.m. UTC | #5
On Fri, Sep 04, 2015 at 11:10:13 +0000, Hahnfeld, Jonas wrote:
> *ping*
> I don't have write access to the repository...

I've committed it to trunk: https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=227489

What about gcc-5-branch?

  -- Ilya
Hahnfeld, Jonas Sept. 4, 2015, 11:26 a.m. UTC | #6
> -----Original Message-----
> From: Ilya Verbin [mailto:iverbin@gmail.com]
> Sent: Friday, September 04, 2015 1:23 PM
> To: Hahnfeld, Jonas; Jakub Jelinek
> Cc: gcc-patches@gcc.gnu.org; Kirill Yukhin
> Subject: Re: Fix intelmic-mkoffload.c if the temp path contains a '-'
> 
> On Fri, Sep 04, 2015 at 11:10:13 +0000, Hahnfeld, Jonas wrote:
> > *ping*
> > I don't have write access to the repository...
> 
> I've committed it to trunk:
> https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=227489
> 
> What about gcc-5-branch?
> 
>   -- Ilya

Thanks!
The bug exists in GCC 5.x as well so the fix should be included in 5.3 if
there will be such a version...

Greetings,
Jonas
Mike Stump Sept. 4, 2015, 7:27 p.m. UTC | #7
On Sep 4, 2015, at 4:10 AM, Hahnfeld, Jonas <Hahnfeld@itc.rwth-aachen.de> wrote:
>>>> 	* intelmic-mkoffload.c (prepare_target_image): Fix if the temp path
>>>> 	contains a '-‘.

So, out of curiosity, did you test all characters other than null?  If - doesn’t work, there is a good chance that no such test has been done, and there is a small hoard of bugs, all the same in there.
Ilya Verbin Sept. 4, 2015, 9:45 p.m. UTC | #8
2015-09-04 22:27 GMT+03:00 Mike Stump <mikestump@comcast.net>:
> On Sep 4, 2015, at 4:10 AM, Hahnfeld, Jonas <Hahnfeld@itc.rwth-aachen.de> wrote:
>>>>>    * intelmic-mkoffload.c (prepare_target_image): Fix if the temp path
>>>>>    contains a '-‘.
>
> So, out of curiosity, did you test all characters other than null?  If - doesn’t work, there is a good chance that no such test has been done, and there is a small hoard of bugs, all the same in there.

Good point.  Objcopy in bfd/binary.c creates symbol names this way:

  for (p = buf; *p; p++)
    if (! ISALNUM (*p))
      *p = '_';

We should do the same in intelmic-mkoffload.c.  I will prepare a patch.

  -- Ilya
Mike Stump Sept. 4, 2015, 10:50 p.m. UTC | #9
On Sep 4, 2015, at 2:45 PM, Ilya Verbin <iverbin@gmail.com> wrote:

> 2015-09-04 22:27 GMT+03:00 Mike Stump <mikestump@comcast.net>:
>> On Sep 4, 2015, at 4:10 AM, Hahnfeld, Jonas <Hahnfeld@itc.rwth-aachen.de> wrote:
>>>>>>   * intelmic-mkoffload.c (prepare_target_image): Fix if the temp path
>>>>>>   contains a '-‘.
>> 
>> So, out of curiosity, did you test all characters other than null?  If - doesn’t work, there is a good chance that no such test has been done, and there is a small hoard of bugs, all the same in there.
> 
> Good point.  Objcopy in bfd/binary.c creates symbol names this way:
> 
>  for (p = buf; *p; p++)
>    if (! ISALNUM (*p))
>      *p = '_’;

So, this code can’t be the code in question, as - is ! ALNUM, and then should have been a _, meaning ‘-‘ would not have to be handled.  Since the code is handling ‘-‘, this can’t be the code in question?
Ilya Verbin Sept. 4, 2015, 11:08 p.m. UTC | #10
2015-09-05 1:50 GMT+03:00 Mike Stump <mikestump@comcast.net>:
>
> On Sep 4, 2015, at 2:45 PM, Ilya Verbin <iverbin@gmail.com> wrote:
>
>> 2015-09-04 22:27 GMT+03:00 Mike Stump <mikestump@comcast.net>:
>>> On Sep 4, 2015, at 4:10 AM, Hahnfeld, Jonas <Hahnfeld@itc.rwth-aachen.de> wrote:
>>>>>>>   * intelmic-mkoffload.c (prepare_target_image): Fix if the temp path
>>>>>>>   contains a '-‘.
>>>
>>> So, out of curiosity, did you test all characters other than null?  If - doesn’t work, there is a good chance that no such test has been done, and there is a small hoard of bugs, all the same in there.
>>
>> Good point.  Objcopy in bfd/binary.c creates symbol names this way:
>>
>>  for (p = buf; *p; p++)
>>    if (! ISALNUM (*p))
>>      *p = '_’;
>
> So, this code can’t be the code in question, as - is ! ALNUM, and then should have been a _, meaning ‘-‘ would not have to be handled.  Since the code is handling ‘-‘, this can’t be the code in question?

When we run "objcopy <args> /tmp-1/liba.so", this code in bfd/binary.c
creates a symbol called "_binary__tmp_1_liba_so_start".  Then
intelmic-mkoffload.c wants to rename it to
"__offload_image_intelmic_start".  To do this, it prepares a string
"--redefine-sym
_binary__tmp_1_liba_so_start=__offload_image_intelmic_start",
therefore it should replace all ! ISALNUM chars in the name, as
objcopy does.

  -- Ilya
diff mbox

Patch

diff --git a/gcc/config/i386/intelmic-mkoffload.c
b/gcc/config/i386/intelmic-mkoffload.c
index ca15868..c9327cf 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -460,7 +460,7 @@  prepare_target_image (const char *target_compiler, int
argc, char **argv)
   for (size_t i = 0; i <= symbol_name_len; i++)
     {
       char c = target_so_filename[i];
-      if ((c == '/') || (c == '.'))
+      if ((c == '/') || (c == '.') || (c == '-'))
 	c = '_';
       symbol_name[i] = c;