2014-06-11 15:57:55

by Gideon D'souza

[permalink] [raw]
Subject: [PATCH] security: Use macros from compiler.h instead of gcc specific attributes

NOTE: Please ignore the earlier similar emails. I apologize sincerely
for the mistake.

To increase compiler portability there is <linux/compiler.h> which
provides convenience macros for various gcc constructs. Eg: __weak for
__attribute__((weak)).

I've taken up the job of cleaning these attributes all over the kernel.
Currently my patches for cleanup of all files under /kernel, /block and
/mm are already done and in the linux 3.15 tree.

In the following patch I've replaced all aforementioned instances under
the /security directory in the kernel source.


Gideon Israel Dsouza (1):
security: Used macros from compiler.h instead of __attribute__((...))

security/selinux/include/security.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

--
1.9.3


2014-06-11 15:58:25

by Gideon D'souza

[permalink] [raw]
Subject: [PATCH 1/1] security: Used macros from compiler.h instead of __attribute__((...))

To increase compiler portability there is <linux/compiler.h> which
provides convenience macros for various gcc constructs. Eg: __packed
for __attribute__((packed)).

This patch is part of a large task I've taken to clean the gcc
specific attributes and use the the macros instead.

Signed-off-by: Gideon Israel Dsouza <[email protected]>
---
security/selinux/include/security.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
index ce7852c..ff19bcc 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -8,6 +8,7 @@
#ifndef _SELINUX_SECURITY_H_
#define _SELINUX_SECURITY_H_

+#include <linux/compiler.h>
#include <linux/dcache.h>
#include <linux/magic.h>
#include <linux/types.h>
@@ -220,7 +221,7 @@ struct selinux_kernel_status {
/*
* The version > 0 supports above members.
*/
-} __attribute__((packed));
+} __packed;

extern void selinux_status_update_setenforce(int enforcing);
extern void selinux_status_update_policyload(int seqno);
--
1.9.3

2014-06-18 18:50:49

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH 1/1] security: Used macros from compiler.h instead of __attribute__((...))

On Wednesday, June 11, 2014 09:25:30 PM Gideon Israel Dsouza wrote:
> To increase compiler portability there is <linux/compiler.h> which
> provides convenience macros for various gcc constructs. Eg: __packed
> for __attribute__((packed)).
>
> This patch is part of a large task I've taken to clean the gcc
> specific attributes and use the the macros instead.
>
> Signed-off-by: Gideon Israel Dsouza <[email protected]>
> ---
> security/selinux/include/security.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)

>From what I can tell this should still work with both the LLVM and Intel
compilers, is that correct?

> diff --git a/security/selinux/include/security.h
> b/security/selinux/include/security.h index ce7852c..ff19bcc 100644
> --- a/security/selinux/include/security.h
> +++ b/security/selinux/include/security.h
> @@ -8,6 +8,7 @@
> #ifndef _SELINUX_SECURITY_H_
> #define _SELINUX_SECURITY_H_
>
> +#include <linux/compiler.h>
> #include <linux/dcache.h>
> #include <linux/magic.h>
> #include <linux/types.h>
> @@ -220,7 +221,7 @@ struct selinux_kernel_status {
> /*
> * The version > 0 supports above members.
> */
> -} __attribute__((packed));
> +} __packed;
>
> extern void selinux_status_update_setenforce(int enforcing);
> extern void selinux_status_update_policyload(int seqno);

--
paul moore
http://www.paul-moore.com

2014-06-18 20:08:16

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 1/1] security: Used macros from compiler.h instead of __attribute__((...))

On Wed, Jun 18, 2014 at 8:50 PM, Paul Moore <[email protected]> wrote:
> On Wednesday, June 11, 2014 09:25:30 PM Gideon Israel Dsouza wrote:
>> To increase compiler portability there is <linux/compiler.h> which
>> provides convenience macros for various gcc constructs. Eg: __packed
>> for __attribute__((packed)).
>>
>> This patch is part of a large task I've taken to clean the gcc
>> specific attributes and use the the macros instead.
>>
>> Signed-off-by: Gideon Israel Dsouza <[email protected]>
>> ---
>> security/selinux/include/security.h | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> From what I can tell this should still work with both the LLVM and Intel
> compilers, is that correct?

That's the idea of the compiler-agnostic attribute macros.

Interestingly, only include/linux/compiler-gcc.h defines __packed.

As it's already in heavy use, I can only assume both LLVM and the Intel
compilers handle both "__packed" (without a special definition) and the
gcc-specific "__attribute__((packed))".

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2014-06-18 20:58:31

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH 1/1] security: Used macros from compiler.h instead of __attribute__((...))

On Wednesday, June 18, 2014 10:08:13 PM Geert Uytterhoeven wrote:
> On Wed, Jun 18, 2014 at 8:50 PM, Paul Moore <[email protected]> wrote:
> > On Wednesday, June 11, 2014 09:25:30 PM Gideon Israel Dsouza wrote:
> >> To increase compiler portability there is <linux/compiler.h> which
> >> provides convenience macros for various gcc constructs. Eg: __packed
> >> for __attribute__((packed)).
> >>
> >> This patch is part of a large task I've taken to clean the gcc
> >> specific attributes and use the the macros instead.
> >>
> >> Signed-off-by: Gideon Israel Dsouza <[email protected]>
> >> ---
> >>
> >> security/selinux/include/security.h | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > From what I can tell this should still work with both the LLVM and Intel
> > compilers, is that correct?
>
> That's the idea of the compiler-agnostic attribute macros.

I just wanted to make sure as I personally only really use gcc and don't
pretend to be up on all the details regarding other compilers.

> Interestingly, only include/linux/compiler-gcc.h defines __packed.

>From what I could tell by looking at the code, the other compilers all define
__GNUC__ so they get the __packed macro as part of the gcc configuration. I
believe the LLVM and Intel compilers would only need to redefine __packed if
they wanted/needed a different definition.

> As it's already in heavy use, I can only assume both LLVM and the Intel
> compilers handle both "__packed" (without a special definition) and the
> gcc-specific "__attribute__((packed))".

Yep, seems reasonable. I'll go ahead and apply the patch.

--
paul moore
http://www.paul-moore.com

2014-06-26 11:45:33

by Gideon D'souza

[permalink] [raw]
Subject: Re: [PATCH 1/1] security: Used macros from compiler.h instead of __attribute__((...))

Hey Paul and Geert,

Sorry I didn't response quick enough, I was out of town on a trip.
Just got back.

Didn't even think of LLVM honestly but that is an excellent point and
I'll try compiling with it.

Paul, thanks for applying my patch.

Regards,
Gideon

On Thu, Jun 19, 2014 at 2:28 AM, Paul Moore <[email protected]> wrote:
> On Wednesday, June 18, 2014 10:08:13 PM Geert Uytterhoeven wrote:
>> On Wed, Jun 18, 2014 at 8:50 PM, Paul Moore <[email protected]> wrote:
>> > On Wednesday, June 11, 2014 09:25:30 PM Gideon Israel Dsouza wrote:
>> >> To increase compiler portability there is <linux/compiler.h> which
>> >> provides convenience macros for various gcc constructs. Eg: __packed
>> >> for __attribute__((packed)).
>> >>
>> >> This patch is part of a large task I've taken to clean the gcc
>> >> specific attributes and use the the macros instead.
>> >>
>> >> Signed-off-by: Gideon Israel Dsouza <[email protected]>
>> >> ---
>> >>
>> >> security/selinux/include/security.h | 3 ++-
>> >> 1 file changed, 2 insertions(+), 1 deletion(-)
>> >
>> > From what I can tell this should still work with both the LLVM and Intel
>> > compilers, is that correct?
>>
>> That's the idea of the compiler-agnostic attribute macros.
>
> I just wanted to make sure as I personally only really use gcc and don't
> pretend to be up on all the details regarding other compilers.
>
>> Interestingly, only include/linux/compiler-gcc.h defines __packed.
>
> From what I could tell by looking at the code, the other compilers all define
> __GNUC__ so they get the __packed macro as part of the gcc configuration. I
> believe the LLVM and Intel compilers would only need to redefine __packed if
> they wanted/needed a different definition.
>
>> As it's already in heavy use, I can only assume both LLVM and the Intel
>> compilers handle both "__packed" (without a special definition) and the
>> gcc-specific "__attribute__((packed))".
>
> Yep, seems reasonable. I'll go ahead and apply the patch.
>
> --
> paul moore
> http://www.paul-moore.com
>