[14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header

Message ID 20221020182603.815-15-luoyonggang@gmail.com
State Superseded
Headers
Series Patches for building with mingw/gcc msvc/clang-cl |

Commit Message

Yonggang Luo Oct. 20, 2022, 6:25 p.m. UTC
  Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 libdw/dwarf_whatattr.c | 3 ++-
 libdw/dwarf_whatform.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
  

Comments

Mark Wielaard Dec. 12, 2022, 1:31 p.m. UTC | #1
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> -
> +#ifndef __OPTIMIZE__
>  unsigned int
>  dwarf_whatattr (Dwarf_Attribute *attr)
>  {
>    return attr == NULL ? 0 : attr->code;
>  }
> +#endif
> diff --git a/libdw/dwarf_whatform.c b/libdw/dwarf_whatform.c
> index dee29a9f..01a33424 100644
> --- a/libdw/dwarf_whatform.c
> +++ b/libdw/dwarf_whatform.c
> @@ -34,9 +34,10 @@
>  #include <dwarf.h>
>  #include "libdwP.h"
>  
> -
> +#ifndef __OPTIMIZE__
>  unsigned int
>  dwarf_whatform (Dwarf_Attribute *attr)
>  {
>    return attr == NULL ? 0 : attr->form;
>  }
> +#endif

I don't think this is correct. These functions are defined with extern
inline (if __OPTIMIZE__ is defined). Which means they will not generate
an out-of-line version. But these functions are exported from libdw, so
there must be a real implementation.

So we want to generate code for these functions whether or not
__OPTIMIZE__ is defined.

Cheers,

Mark
  
lilydjwg--- via Elfutils-devel Dec. 16, 2022, 9:47 p.m. UTC | #2
From bdf8a3b45f063d010e7c93b3d3bfc42b801ee9b2 Mon Sep 17 00:00:00 2001
From: Yonggang Luo <luoyonggang@gmail.com>
Date: Thu, 20 Oct 2022 02:50:03 +0800
Subject: [PATCH] libdw: Fixes compile of dwarf_whatattr.c and
dwarf_whatform.c

If __OPTIMIZE__ is defined, then compile  dwarf_whatattr.c and
dwarf_whatform.c
will cause symbol conflict between
dwarf_whatattr.c and libdw.h,
dwarf_whatform.c and libdw.h,

So always undefined __OPTIMIZE__ when compiling these two files

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 libdw/dwarf_whatattr.c | 4 +++-
 libdw/dwarf_whatform.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libdw/dwarf_whatattr.c b/libdw/dwarf_whatattr.c
index d664b021..c016f293 100644
--- a/libdw/dwarf_whatattr.c
+++ b/libdw/dwarf_whatattr.c
@@ -30,7 +30,9 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+#ifdef __OPTIMIZE__
+#undef __OPTIMIZE__
+#endif
 #include <dwarf.h>
 #include "libdwP.h"

diff --git a/libdw/dwarf_whatform.c b/libdw/dwarf_whatform.c
index dee29a9f..f1d3574d 100644
--- a/libdw/dwarf_whatform.c
+++ b/libdw/dwarf_whatform.c
@@ -30,7 +30,9 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+#ifdef __OPTIMIZE__
+#undef __OPTIMIZE__
+#endif
 #include <dwarf.h>
 #include "libdwP.h"
  
Mark Wielaard Dec. 20, 2022, 3:08 p.m. UTC | #3
On Sat, 2022-12-17 at 05:47 +0800, 罗勇刚(Yonggang Luo) wrote:
> From bdf8a3b45f063d010e7c93b3d3bfc42b801ee9b2 Mon Sep 17 00:00:00
> 2001
> From: Yonggang Luo <luoyonggang@gmail.com>
> Date: Thu, 20 Oct 2022 02:50:03 +0800
> Subject: [PATCH] libdw: Fixes compile of dwarf_whatattr.c and
> dwarf_whatform.c
> 
> If __OPTIMIZE__ is defined, then compile  dwarf_whatattr.c and
> dwarf_whatform.c
> will cause symbol conflict between
> dwarf_whatattr.c and libdw.h,
> dwarf_whatform.c and libdw.h,
> 
> So always undefined __OPTIMIZE__ when compiling these two files

I don't think this is correct either. Some system headers might depend
on __OPTIMIZE__ being defined. Are you using a compiler that doesn't
define __OPTIMIZE__ ?

Cheers,

Mark
  
lilydjwg--- via Elfutils-devel Dec. 20, 2022, 4:31 p.m. UTC | #4
On Tue, Dec 20, 2022 at 11:08 PM Mark Wielaard <mark@klomp.org> wrote:
>
> On Sat, 2022-12-17 at 05:47 +0800, 罗勇刚(Yonggang Luo) wrote:
> > From bdf8a3b45f063d010e7c93b3d3bfc42b801ee9b2 Mon Sep 17 00:00:00
> > 2001
> > From: Yonggang Luo <luoyonggang@gmail.com>
> > Date: Thu, 20 Oct 2022 02:50:03 +0800
> > Subject: [PATCH] libdw: Fixes compile of dwarf_whatattr.c and
> > dwarf_whatform.c
> >
> > If __OPTIMIZE__ is defined, then compile  dwarf_whatattr.c and
> > dwarf_whatform.c
> > will cause symbol conflict between
> > dwarf_whatattr.c and libdw.h,
> > dwarf_whatform.c and libdw.h,
> >
> > So always undefined __OPTIMIZE__ when compiling these two files
>
> I don't think this is correct either. Some system headers might depend
> on __OPTIMIZE__ being defined. Are you using a compiler that doesn't
> define __OPTIMIZE__ ?

In debug mode, __OPTIMIZE__   won't be defined.


>
> Cheers,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
  

Patch

diff --git a/libdw/dwarf_whatattr.c b/libdw/dwarf_whatattr.c
index d664b021..59769865 100644
--- a/libdw/dwarf_whatattr.c
+++ b/libdw/dwarf_whatattr.c
@@ -34,9 +34,10 @@ 
 #include <dwarf.h>
 #include "libdwP.h"
 
-
+#ifndef __OPTIMIZE__
 unsigned int
 dwarf_whatattr (Dwarf_Attribute *attr)
 {
   return attr == NULL ? 0 : attr->code;
 }
+#endif
diff --git a/libdw/dwarf_whatform.c b/libdw/dwarf_whatform.c
index dee29a9f..01a33424 100644
--- a/libdw/dwarf_whatform.c
+++ b/libdw/dwarf_whatform.c
@@ -34,9 +34,10 @@ 
 #include <dwarf.h>
 #include "libdwP.h"
 
-
+#ifndef __OPTIMIZE__
 unsigned int
 dwarf_whatform (Dwarf_Attribute *attr)
 {
   return attr == NULL ? 0 : attr->form;
 }
+#endif