Message ID | 20211222181607.1203191-3-andre.przywara@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Various (build system) fixes | expand |
On Wed, Dec 22, 2021 at 06:16:00PM +0000, Andre Przywara wrote: > So far we were relying on some standard C headers to be provided by the > toolchain. This applies for instance to stddef.h and stdint.h. > As a "bare-metal" application, we should not rely on external headers, > or even on a toolchain providing them in the first place. > > Define our own version of stddef.h and stdint.h, containing just the > types that we actually need. Even a freestanding compiler implementation is required to provide these headers, and using the compiler versions would avoid unexpected mismatches (e.g. for builtins). So I don't think the justification as written makes sense. Is this because the next patch removes the stdinc paths, and so we don't get the compiler's implementation of these headers? Thanks, Mark. > > Signed-off-by: Andre Przywara <andre.przywara@arm.com> > --- > arch/aarch32/include/stdint.h | 19 +++++++++++++++++++ > arch/aarch64/include/stdint.h | 19 +++++++++++++++++++ > include/stddef.h | 15 +++++++++++++++ > 3 files changed, 53 insertions(+) > create mode 100644 arch/aarch32/include/stdint.h > create mode 100644 arch/aarch64/include/stdint.h > create mode 100644 include/stddef.h > > diff --git a/arch/aarch32/include/stdint.h b/arch/aarch32/include/stdint.h > new file mode 100644 > index 0000000..77546f0 > --- /dev/null > +++ b/arch/aarch32/include/stdint.h > @@ -0,0 +1,19 @@ > +/* > + * arch/aarch32/include/stdint.h > + * > + * Copyright (C) 2021 ARM Limited. All rights reserved. > + * > + * Use of this source code is governed by a BSD-style license that can be > + * found in the LICENSE.txt file. > + */ > +#ifndef STDINT_H__ > +#define STDINT_H__ > + > +typedef unsigned char uint8_t; > +typedef unsigned short int uint16_t; > +typedef unsigned int uint32_t; > +typedef unsigned long long int uint64_t; > + > +typedef unsigned int uintptr_t; > + > +#endif > diff --git a/arch/aarch64/include/stdint.h b/arch/aarch64/include/stdint.h > new file mode 100644 > index 0000000..92c2603 > --- /dev/null > +++ b/arch/aarch64/include/stdint.h > @@ -0,0 +1,19 @@ > +/* > + * arch/aarch64/include/stdint.h > + * > + * Copyright (C) 2021 ARM Limited. All rights reserved. > + * > + * Use of this source code is governed by a BSD-style license that can be > + * found in the LICENSE.txt file. > + */ > +#ifndef STDINT_H__ > +#define STDINT_H__ > + > +typedef unsigned char uint8_t; > +typedef unsigned short int uint16_t; > +typedef unsigned int uint32_t; > +typedef unsigned long int uint64_t; > + > +typedef unsigned long int uintptr_t; > + > +#endif > diff --git a/include/stddef.h b/include/stddef.h > new file mode 100644 > index 0000000..3208b10 > --- /dev/null > +++ b/include/stddef.h > @@ -0,0 +1,15 @@ > +/* > + * include/stddef.h - standard data type definitions > + * > + * Copyright (C) 2021 ARM Limited. All rights reserved. > + * > + * Use of this source code is governed by a BSD-style license that can be > + * found in the LICENSE.txt file. > + */ > +#ifndef STDDEF_H__ > +#define STDDEF_H__ > + > +typedef unsigned long int size_t; > +typedef signed long int ssize_t; > + > +#endif > -- > 2.25.1 >
On Fri, 7 Jan 2022 13:49:43 +0000 Mark Rutland <mark.rutland@arm.com> wrote: > On Wed, Dec 22, 2021 at 06:16:00PM +0000, Andre Przywara wrote: > > So far we were relying on some standard C headers to be provided by the > > toolchain. This applies for instance to stddef.h and stdint.h. > > As a "bare-metal" application, we should not rely on external headers, > > or even on a toolchain providing them in the first place. > > > > Define our own version of stddef.h and stdint.h, containing just the > > types that we actually need. > > Even a freestanding compiler implementation is required to provide these > headers, and using the compiler versions would avoid unexpected mismatches > (e.g. for builtins). So I don't think the justification as written makes sense. > > Is this because the next patch removes the stdinc paths, and so we don't get > the compiler's implementation of these headers? Yes, exactly. I don't like repeating those either, and understand that even a minimal compiler carries these headers, *somewhere*, but I couldn't find an easy way of including them without being compiler/build specific. I can try harder, and would be happy if someone points out the real solution to this. For the sake of solving this problem I figured that those particular definitions are actually somewhat generic (for all practical purposes), so it was the least involved solution to the real problem, which is to ditch the *other* compiler headers and libraries, as done in patch 3/9. Cheers, Andre > > > > Signed-off-by: Andre Przywara <andre.przywara@arm.com> > > --- > > arch/aarch32/include/stdint.h | 19 +++++++++++++++++++ > > arch/aarch64/include/stdint.h | 19 +++++++++++++++++++ > > include/stddef.h | 15 +++++++++++++++ > > 3 files changed, 53 insertions(+) > > create mode 100644 arch/aarch32/include/stdint.h > > create mode 100644 arch/aarch64/include/stdint.h > > create mode 100644 include/stddef.h > > > > diff --git a/arch/aarch32/include/stdint.h b/arch/aarch32/include/stdint.h > > new file mode 100644 > > index 0000000..77546f0 > > --- /dev/null > > +++ b/arch/aarch32/include/stdint.h > > @@ -0,0 +1,19 @@ > > +/* > > + * arch/aarch32/include/stdint.h > > + * > > + * Copyright (C) 2021 ARM Limited. All rights reserved. > > + * > > + * Use of this source code is governed by a BSD-style license that can be > > + * found in the LICENSE.txt file. > > + */ > > +#ifndef STDINT_H__ > > +#define STDINT_H__ > > + > > +typedef unsigned char uint8_t; > > +typedef unsigned short int uint16_t; > > +typedef unsigned int uint32_t; > > +typedef unsigned long long int uint64_t; > > + > > +typedef unsigned int uintptr_t; > > + > > +#endif > > diff --git a/arch/aarch64/include/stdint.h b/arch/aarch64/include/stdint.h > > new file mode 100644 > > index 0000000..92c2603 > > --- /dev/null > > +++ b/arch/aarch64/include/stdint.h > > @@ -0,0 +1,19 @@ > > +/* > > + * arch/aarch64/include/stdint.h > > + * > > + * Copyright (C) 2021 ARM Limited. All rights reserved. > > + * > > + * Use of this source code is governed by a BSD-style license that can be > > + * found in the LICENSE.txt file. > > + */ > > +#ifndef STDINT_H__ > > +#define STDINT_H__ > > + > > +typedef unsigned char uint8_t; > > +typedef unsigned short int uint16_t; > > +typedef unsigned int uint32_t; > > +typedef unsigned long int uint64_t; > > + > > +typedef unsigned long int uintptr_t; > > + > > +#endif > > diff --git a/include/stddef.h b/include/stddef.h > > new file mode 100644 > > index 0000000..3208b10 > > --- /dev/null > > +++ b/include/stddef.h > > @@ -0,0 +1,15 @@ > > +/* > > + * include/stddef.h - standard data type definitions > > + * > > + * Copyright (C) 2021 ARM Limited. All rights reserved. > > + * > > + * Use of this source code is governed by a BSD-style license that can be > > + * found in the LICENSE.txt file. > > + */ > > +#ifndef STDDEF_H__ > > +#define STDDEF_H__ > > + > > +typedef unsigned long int size_t; > > +typedef signed long int ssize_t; > > + > > +#endif > > -- > > 2.25.1 > >
On Fri, Jan 07, 2022 at 02:31:28PM +0000, Andre Przywara wrote: > On Fri, 7 Jan 2022 13:49:43 +0000 > Mark Rutland <mark.rutland@arm.com> wrote: > > > On Wed, Dec 22, 2021 at 06:16:00PM +0000, Andre Przywara wrote: > > > So far we were relying on some standard C headers to be provided by the > > > toolchain. This applies for instance to stddef.h and stdint.h. > > > As a "bare-metal" application, we should not rely on external headers, > > > or even on a toolchain providing them in the first place. > > > > > > Define our own version of stddef.h and stdint.h, containing just the > > > types that we actually need. > > > > Even a freestanding compiler implementation is required to provide these > > headers, and using the compiler versions would avoid unexpected mismatches > > (e.g. for builtins). So I don't think the justification as written makes sense. > > > > Is this because the next patch removes the stdinc paths, and so we don't get > > the compiler's implementation of these headers? > > Yes, exactly. I don't like repeating those either, and understand that > even a minimal compiler carries these headers, *somewhere*, but I couldn't > find an easy way of including them without being compiler/build specific. > > I can try harder, and would be happy if someone points out the real > solution to this. > > For the sake of solving this problem I figured that those particular > definitions are actually somewhat generic (for all practical purposes), so > it was the least involved solution to the real problem, which is to ditch > the *other* compiler headers and libraries, as done in patch 3/9. FWIW, if we do need to use -nostdinc to drop other headers, I'm happy to take something like this, but I think that should be an atomic change -- we should add -nostdinc and the headers at the same time, and be explicit in the commit message as to the rationale. I'm just torn as to whether we actually need -nostdinc, as IIUC we don't strictly need to drop that for freestanding code, and IIRC we haven't had any mistakes so far that stemmed from including headers that weren't suitable for freestanding code. So I'm tempted to say keep the standard includes for now. Thanks, Mark. > > Cheers, > Andre > > > > > > > Signed-off-by: Andre Przywara <andre.przywara@arm.com> > > > --- > > > arch/aarch32/include/stdint.h | 19 +++++++++++++++++++ > > > arch/aarch64/include/stdint.h | 19 +++++++++++++++++++ > > > include/stddef.h | 15 +++++++++++++++ > > > 3 files changed, 53 insertions(+) > > > create mode 100644 arch/aarch32/include/stdint.h > > > create mode 100644 arch/aarch64/include/stdint.h > > > create mode 100644 include/stddef.h > > > > > > diff --git a/arch/aarch32/include/stdint.h b/arch/aarch32/include/stdint.h > > > new file mode 100644 > > > index 0000000..77546f0 > > > --- /dev/null > > > +++ b/arch/aarch32/include/stdint.h > > > @@ -0,0 +1,19 @@ > > > +/* > > > + * arch/aarch32/include/stdint.h > > > + * > > > + * Copyright (C) 2021 ARM Limited. All rights reserved. > > > + * > > > + * Use of this source code is governed by a BSD-style license that can be > > > + * found in the LICENSE.txt file. > > > + */ > > > +#ifndef STDINT_H__ > > > +#define STDINT_H__ > > > + > > > +typedef unsigned char uint8_t; > > > +typedef unsigned short int uint16_t; > > > +typedef unsigned int uint32_t; > > > +typedef unsigned long long int uint64_t; > > > + > > > +typedef unsigned int uintptr_t; > > > + > > > +#endif > > > diff --git a/arch/aarch64/include/stdint.h b/arch/aarch64/include/stdint.h > > > new file mode 100644 > > > index 0000000..92c2603 > > > --- /dev/null > > > +++ b/arch/aarch64/include/stdint.h > > > @@ -0,0 +1,19 @@ > > > +/* > > > + * arch/aarch64/include/stdint.h > > > + * > > > + * Copyright (C) 2021 ARM Limited. All rights reserved. > > > + * > > > + * Use of this source code is governed by a BSD-style license that can be > > > + * found in the LICENSE.txt file. > > > + */ > > > +#ifndef STDINT_H__ > > > +#define STDINT_H__ > > > + > > > +typedef unsigned char uint8_t; > > > +typedef unsigned short int uint16_t; > > > +typedef unsigned int uint32_t; > > > +typedef unsigned long int uint64_t; > > > + > > > +typedef unsigned long int uintptr_t; > > > + > > > +#endif > > > diff --git a/include/stddef.h b/include/stddef.h > > > new file mode 100644 > > > index 0000000..3208b10 > > > --- /dev/null > > > +++ b/include/stddef.h > > > @@ -0,0 +1,15 @@ > > > +/* > > > + * include/stddef.h - standard data type definitions > > > + * > > > + * Copyright (C) 2021 ARM Limited. All rights reserved. > > > + * > > > + * Use of this source code is governed by a BSD-style license that can be > > > + * found in the LICENSE.txt file. > > > + */ > > > +#ifndef STDDEF_H__ > > > +#define STDDEF_H__ > > > + > > > +typedef unsigned long int size_t; > > > +typedef signed long int ssize_t; > > > + > > > +#endif > > > -- > > > 2.25.1 > > > >
diff --git a/arch/aarch32/include/stdint.h b/arch/aarch32/include/stdint.h new file mode 100644 index 0000000..77546f0 --- /dev/null +++ b/arch/aarch32/include/stdint.h @@ -0,0 +1,19 @@ +/* + * arch/aarch32/include/stdint.h + * + * Copyright (C) 2021 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ +#ifndef STDINT_H__ +#define STDINT_H__ + +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; + +typedef unsigned int uintptr_t; + +#endif diff --git a/arch/aarch64/include/stdint.h b/arch/aarch64/include/stdint.h new file mode 100644 index 0000000..92c2603 --- /dev/null +++ b/arch/aarch64/include/stdint.h @@ -0,0 +1,19 @@ +/* + * arch/aarch64/include/stdint.h + * + * Copyright (C) 2021 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ +#ifndef STDINT_H__ +#define STDINT_H__ + +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long int uint64_t; + +typedef unsigned long int uintptr_t; + +#endif diff --git a/include/stddef.h b/include/stddef.h new file mode 100644 index 0000000..3208b10 --- /dev/null +++ b/include/stddef.h @@ -0,0 +1,15 @@ +/* + * include/stddef.h - standard data type definitions + * + * Copyright (C) 2021 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ +#ifndef STDDEF_H__ +#define STDDEF_H__ + +typedef unsigned long int size_t; +typedef signed long int ssize_t; + +#endif
So far we were relying on some standard C headers to be provided by the toolchain. This applies for instance to stddef.h and stdint.h. As a "bare-metal" application, we should not rely on external headers, or even on a toolchain providing them in the first place. Define our own version of stddef.h and stdint.h, containing just the types that we actually need. Signed-off-by: Andre Przywara <andre.przywara@arm.com> --- arch/aarch32/include/stdint.h | 19 +++++++++++++++++++ arch/aarch64/include/stdint.h | 19 +++++++++++++++++++ include/stddef.h | 15 +++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 arch/aarch32/include/stdint.h create mode 100644 arch/aarch64/include/stdint.h create mode 100644 include/stddef.h