bfd: add missing include <time.h>

Message ID 20240313103728.1253706-1-chigot@adacore.com
State New
Headers
Series bfd: add missing include <time.h> |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed

Commit Message

Clément Chigot March 13, 2024, 10:37 a.m. UTC
  bdfio.c is defining bfd_get_current_time which is returning a time_t.
This type is defined in time.h and thus, must be included in bfd main
header to avoid undefined type when include bfd.h.

Note that most of the time, <time.h> is pulled by <sys/stat.h> already
included in bfd.h. That's why it went unnoticed.
---
 bfd/bfd-in.h  | 1 +
 bfd/bfd-in2.h | 1 +
 2 files changed, 2 insertions(+)
  

Comments

Clément Chigot March 14, 2024, 12:46 p.m. UTC | #1
Hi Nick,

This patch looks trivial. Though, I'm wondering if binutils might
support some non-posix systems where this new include could trigger
issues. Do you think this could be the case ?

Clément

On Wed, Mar 13, 2024 at 11:37 AM Clément Chigot <chigot@adacore.com> wrote:
>
> bdfio.c is defining bfd_get_current_time which is returning a time_t.
> This type is defined in time.h and thus, must be included in bfd main
> header to avoid undefined type when include bfd.h.
>
> Note that most of the time, <time.h> is pulled by <sys/stat.h> already
> included in bfd.h. That's why it went unnoticed.
> ---
>  bfd/bfd-in.h  | 1 +
>  bfd/bfd-in2.h | 1 +
>  2 files changed, 2 insertions(+)
>
> diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
> index 0ff1e2f3ed5..04e65aad5f0 100644
> --- a/bfd/bfd-in.h
> +++ b/bfd/bfd-in.h
> @@ -36,6 +36,7 @@ extern "C" {
>  #include "symcat.h"
>  #include <stdint.h>
>  #include <stdbool.h>
> +#include <time.h>
>  #include "diagnostics.h"
>  #include <stdarg.h>
>  #include <string.h>
> diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
> index a335df522d2..eb58b674d25 100644
> --- a/bfd/bfd-in2.h
> +++ b/bfd/bfd-in2.h
> @@ -44,6 +44,7 @@ extern "C" {
>  #include "symcat.h"
>  #include <stdint.h>
>  #include <stdbool.h>
> +#include <time.h>
>  #include "diagnostics.h"
>  #include <stdarg.h>
>  #include <string.h>
> --
> 2.25.1
>
  
Tom Tromey March 15, 2024, 3:39 p.m. UTC | #2
>>>>> "Clément" == Clément Chigot <chigot@adacore.com> writes:

Clément> This patch looks trivial. Though, I'm wondering if binutils might
Clément> support some non-posix systems where this new include could trigger
Clément> issues. Do you think this could be the case ?

FWIW a good resource for answering this kind of question is the gnulib
manual.  It normally documents when a header is missing or when it
doesn't define something that it ought to.

On this basis time.h seems safe:

https://www.gnu.org/software/gnulib/manual/html_node/time_002eh.html

Tom
  
Nick Clifton March 18, 2024, 11:49 a.m. UTC | #3
Hi Clément,

> bdfio.c is defining bfd_get_current_time which is returning a time_t.
> This type is defined in time.h and thus, must be included in bfd main
> header to avoid undefined type when include bfd.h.
> 
> Note that most of the time, <time.h> is pulled by <sys/stat.h> already
> included in bfd.h. That's why it went unnoticed.

Ah - that explains it.

Patch approved - please apply.

Cheers
   Nick
  
Nick Clifton March 18, 2024, 11:49 a.m. UTC | #4
Hi Tom,

> Clément> This patch looks trivial. Though, I'm wondering if binutils might
> Clément> support some non-posix systems where this new include could trigger
> Clément> issues. Do you think this could be the case ?
> 
> FWIW a good resource for answering this kind of question is the gnulib
> manual.  It normally documents when a header is missing or when it
> doesn't define something that it ought to.
> 
> On this basis time.h seems safe:
> 
> https://www.gnu.org/software/gnulib/manual/html_node/time_002eh.html

Thanks for the tip and for checking. :-)

Cheers
   Nick
  

Patch

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 0ff1e2f3ed5..04e65aad5f0 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -36,6 +36,7 @@  extern "C" {
 #include "symcat.h"
 #include <stdint.h>
 #include <stdbool.h>
+#include <time.h>
 #include "diagnostics.h"
 #include <stdarg.h>
 #include <string.h>
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index a335df522d2..eb58b674d25 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -44,6 +44,7 @@  extern "C" {
 #include "symcat.h"
 #include <stdint.h>
 #include <stdbool.h>
+#include <time.h>
 #include "diagnostics.h"
 #include <stdarg.h>
 #include <string.h>