public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elflint: fix undefined 'buffer_left' reference
@ 2021-06-06 22:57 Sergei Trofimovich
  2021-06-06 23:38 ` Dmitry V. Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Sergei Trofimovich @ 2021-06-06 22:57 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Sergei Trofimovich

Link failure is reproducible on gcc-11.1.0 target:

```
$ autoreconf -i -f
$ ./configure --enable-maintainer-mode --disable-debuginfod \
    --host=x86_64-pc-linux-gnu \
    CFLAGS=-march=znver3 \
    CXXFLAGS=-march=znver3 \
    LDFLAGS=" "
$ make

  CCLD     elflint
ld: elflint.o: in function `check_attributes':
elflint.c:(.text+0xdcff): undefined reference to `buffer_left'
ld: elflint.c:(.text+0xe557): undefined reference to `buffer_left'
```

It happens due to possible external linkage of `buffer_left()`.

The change forces local linkkage to always use local definition
(either inline or out-of-line).

Reported-by: Toralf Förster
Bug: https://bugs.gentoo.org/794601
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
---
 src/ChangeLog | 5 +++++
 src/elflint.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 2c7be185..e030de0d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2021-06-06  Sergei Trofimovich  <slyfox@gentoo.org>
+
+	* elflint.c (buffer_left): Mark as 'inline' to avoid external linkage
+	failure.
+
 2021-05-12  Dmitry V. Levin  <ldv@altlinux.org>
 
 	* elfcompress.c (process_file): Return 1 instead of -1 in case of an
diff --git a/src/elflint.c b/src/elflint.c
index 85cc7833..35b40500 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -3434,7 +3434,7 @@ buffer_pos (Elf_Data *data, const unsigned char *p)
   return p - (const unsigned char *) data->d_buf;
 }
 
-inline size_t
+static inline size_t
 buffer_left (Elf_Data *data, const unsigned char *p)
 {
   return (const unsigned char *) data->d_buf + data->d_size - p;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] elflint: fix undefined 'buffer_left' reference
  2021-06-06 22:57 [PATCH] elflint: fix undefined 'buffer_left' reference Sergei Trofimovich
@ 2021-06-06 23:38 ` Dmitry V. Levin
  2021-06-07 21:37   ` [PATCH v2] " Sergei Trofimovich
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry V. Levin @ 2021-06-06 23:38 UTC (permalink / raw)
  To: Sergei Trofimovich; +Cc: elfutils-devel

Hi,

On Sun, Jun 06, 2021 at 11:57:09PM +0100, Sergei Trofimovich via Elfutils-devel wrote:
> Link failure is reproducible on gcc-11.1.0 target:
> 
> ```
> $ autoreconf -i -f
> $ ./configure --enable-maintainer-mode --disable-debuginfod \
>     --host=x86_64-pc-linux-gnu \
>     CFLAGS=-march=znver3 \
>     CXXFLAGS=-march=znver3 \
>     LDFLAGS=" "
> $ make
> 
>   CCLD     elflint
> ld: elflint.o: in function `check_attributes':
> elflint.c:(.text+0xdcff): undefined reference to `buffer_left'
> ld: elflint.c:(.text+0xe557): undefined reference to `buffer_left'
> ```
> 
> It happens due to possible external linkage of `buffer_left()`.
> 
> The change forces local linkkage to always use local definition
> (either inline or out-of-line).
> 
> Reported-by: Toralf Förster
> Bug: https://bugs.gentoo.org/794601
> Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

Fixes: e95d1fbb ("elflint: Pull left() in file scope")

> ---
>  src/ChangeLog | 5 +++++
>  src/elflint.c | 2 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ChangeLog b/src/ChangeLog
> index 2c7be185..e030de0d 100644
> --- a/src/ChangeLog
> +++ b/src/ChangeLog
> @@ -1,3 +1,8 @@
> +2021-06-06  Sergei Trofimovich  <slyfox@gentoo.org>
> +
> +	* elflint.c (buffer_left): Mark as 'inline' to avoid external linkage
> +	failure.

Did you mean 'static'?

> +
>  2021-05-12  Dmitry V. Levin  <ldv@altlinux.org>
>  
>  	* elfcompress.c (process_file): Return 1 instead of -1 in case of an
> diff --git a/src/elflint.c b/src/elflint.c
> index 85cc7833..35b40500 100644
> --- a/src/elflint.c
> +++ b/src/elflint.c
> @@ -3434,7 +3434,7 @@ buffer_pos (Elf_Data *data, const unsigned char *p)
>    return p - (const unsigned char *) data->d_buf;
>  }
>  
> -inline size_t
> +static inline size_t
>  buffer_left (Elf_Data *data, const unsigned char *p)
>  {
>    return (const unsigned char *) data->d_buf + data->d_size - p;

I suppose we could simply replace these 'inline' with 'static'
and let the compiler decide whether to inline or not.


-- 
ldv

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] elflint: fix undefined 'buffer_left' reference
  2021-06-06 23:38 ` Dmitry V. Levin
@ 2021-06-07 21:37   ` Sergei Trofimovich
  2021-06-07 22:10     ` Dmitry V. Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Sergei Trofimovich @ 2021-06-07 21:37 UTC (permalink / raw)
  To: elfutils-devel, Dmitry V. Levin; +Cc: Sergei Trofimovich

Link failure is reproducible on gcc-11.1.0 target:

```
$ autoreconf -i -f
$ ./configure --enable-maintainer-mode --disable-debuginfod \
    --host=x86_64-pc-linux-gnu \
    CFLAGS=-march=znver3 \
    CXXFLAGS=-march=znver3 \
    LDFLAGS=" "
$ make

  CCLD     elflint
ld: elflint.o: in function `check_attributes':
elflint.c:(.text+0xdcff): undefined reference to `buffer_left'
ld: elflint.c:(.text+0xe557): undefined reference to `buffer_left'
```

It happens due to possible external linkage of `buffer_left()`.

The change forces local linkkage to always use local definition
(either inline or out-of-line).

Reported-by: Toralf Förster
Bug: https://bugs.gentoo.org/794601
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Fixes: e95d1fbb ("elflint: Pull left() in file scope")
---
Change since v1 suggested by Dmitry:
- fixed changelog to spell 'static' correctly :)
- added 'Fixes' annotation

Did not drop 'inline' to be consistent with other tiny helpers
in the same file.

 src/ChangeLog | 5 +++++
 src/elflint.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 2c7be185..698b3c77 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2021-06-06  Sergei Trofimovich  <slyfox@gentoo.org>
+
+	* elflint.c (buffer_left): Mark as 'static' to avoid external linkage
+	failure.
+
 2021-05-12  Dmitry V. Levin  <ldv@altlinux.org>
 
 	* elfcompress.c (process_file): Return 1 instead of -1 in case of an
diff --git a/src/elflint.c b/src/elflint.c
index 85cc7833..35b40500 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -3434,7 +3434,7 @@ buffer_pos (Elf_Data *data, const unsigned char *p)
   return p - (const unsigned char *) data->d_buf;
 }
 
-inline size_t
+static inline size_t
 buffer_left (Elf_Data *data, const unsigned char *p)
 {
   return (const unsigned char *) data->d_buf + data->d_size - p;
-- 
2.32.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] elflint: fix undefined 'buffer_left' reference
  2021-06-07 21:37   ` [PATCH v2] " Sergei Trofimovich
@ 2021-06-07 22:10     ` Dmitry V. Levin
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry V. Levin @ 2021-06-07 22:10 UTC (permalink / raw)
  To: Sergei Trofimovich; +Cc: elfutils-devel

On Mon, Jun 07, 2021 at 10:37:42PM +0100, Sergei Trofimovich wrote:
> Link failure is reproducible on gcc-11.1.0 target:
> 
> ```
> $ autoreconf -i -f
> $ ./configure --enable-maintainer-mode --disable-debuginfod \
>     --host=x86_64-pc-linux-gnu \
>     CFLAGS=-march=znver3 \
>     CXXFLAGS=-march=znver3 \
>     LDFLAGS=" "
> $ make
> 
>   CCLD     elflint
> ld: elflint.o: in function `check_attributes':
> elflint.c:(.text+0xdcff): undefined reference to `buffer_left'
> ld: elflint.c:(.text+0xe557): undefined reference to `buffer_left'
> ```
> 
> It happens due to possible external linkage of `buffer_left()`.
> 
> The change forces local linkkage to always use local definition
> (either inline or out-of-line).
> 
> Reported-by: Toralf Förster
> Bug: https://bugs.gentoo.org/794601
> Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
> Fixes: e95d1fbb ("elflint: Pull left() in file scope")
> ---
> Change since v1 suggested by Dmitry:
> - fixed changelog to spell 'static' correctly :)
> - added 'Fixes' annotation
> 
> Did not drop 'inline' to be consistent with other tiny helpers
> in the same file.
> 
>  src/ChangeLog | 5 +++++
>  src/elflint.c | 2 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ChangeLog b/src/ChangeLog
> index 2c7be185..698b3c77 100644
> --- a/src/ChangeLog
> +++ b/src/ChangeLog
> @@ -1,3 +1,8 @@
> +2021-06-06  Sergei Trofimovich  <slyfox@gentoo.org>
> +
> +	* elflint.c (buffer_left): Mark as 'static' to avoid external linkage
> +	failure.
> +
>  2021-05-12  Dmitry V. Levin  <ldv@altlinux.org>
>  
>  	* elfcompress.c (process_file): Return 1 instead of -1 in case of an
> diff --git a/src/elflint.c b/src/elflint.c
> index 85cc7833..35b40500 100644
> --- a/src/elflint.c
> +++ b/src/elflint.c
> @@ -3434,7 +3434,7 @@ buffer_pos (Elf_Data *data, const unsigned char *p)
>    return p - (const unsigned char *) data->d_buf;
>  }
>  
> -inline size_t
> +static inline size_t
>  buffer_left (Elf_Data *data, const unsigned char *p)
>  {
>    return (const unsigned char *) data->d_buf + data->d_size - p;

Applied, thanks.


-- 
ldv

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-07 22:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-06 22:57 [PATCH] elflint: fix undefined 'buffer_left' reference Sergei Trofimovich
2021-06-06 23:38 ` Dmitry V. Levin
2021-06-07 21:37   ` [PATCH v2] " Sergei Trofimovich
2021-06-07 22:10     ` Dmitry V. Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).