linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mod/file2alias: make modpost compile on darwin again
@ 2012-02-22 21:55 Andreas Bießmann
  2012-02-22 23:08 ` Rusty Russell
  2012-02-24  7:23 ` [PATCH v2] " Andreas Bießmann
  0 siblings, 2 replies; 8+ messages in thread
From: Andreas Bießmann @ 2012-02-22 21:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andreas Bießmann, Rusty Russell, Greg Kroah-Hartman,
	Jochen Friedrich, Samuel Ortiz, K. Y. Srinivasan

commit e49ce14150c64b29a8dd211df785576fa19a9858 breaks cross compiling
the linux kernel on darwin hosts.
This fix introduce some minimal glue to adopt linker section handling
for darwin hosts.

Additionally this patch fixes minor chackpatch warnings introduced by
mentioned commit.

Signed-off-by: Andreas Bießmann <andreas@biessmann.de>
CC: Rusty Russell <rusty@rustcorp.com.au>
CC: Greg Kroah-Hartman <gregkh@suse.de>
CC: Jochen Friedrich <jochen@scram.de>
CC: Samuel Ortiz <sameo@linux.intel.com>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
---
 scripts/mod/file2alias.c |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index d0de2a2..d2f42eb 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -46,11 +46,37 @@ struct devtable {
 	void *function;
 };
 
+#define ___cat(a, b) a ## b
+#define __cat(a, b) ___cat(a, b)
+
+/* we need some special handling for this host tool running eventually on
+ * Darwin. The Mach-O section handling is a bit different than ELF section
+ * handling. The differnces in detail are:
+ *  a) we have segments which have sections
+ *  b) we need a API call to get the respective section symbols */
+#if defined(__MACH__)
+#include <mach-o/getsect.h>
+
+#define INIT_SECTION(name)  do {					\
+		unsigned long name ## _len;				\
+		char *__cat(pstart_, name) = getsectdata("__TEXT",	\
+			#name, &__cat(name, _len));			\
+		char *__cat(pstop_, name) = __cat(pstart_, name) +	\
+			__cat(name, _len);				\
+		__cat(__start_, name) = (void *)__cat(pstart_, name);	\
+		__cat(__stop_, name) = (void *)__cat(pstop_, name);	\
+	} while (0)
+#define SECTION(name)   __attribute__((section("__TEXT, " #name)))
+
+struct devtable **__start___devtable, **__stop___devtable;
+#else
+#define INIT_SECTION(name) /* no-op for ELF */
+#define SECTION(name)   __attribute__((section(#name)))
+
 /* We construct a table of pointers in an ELF section (pointers generally
  * go unpadded by gcc).  ld creates boundary syms for us. */
 extern struct devtable *__start___devtable[], *__stop___devtable[];
-#define ___cat(a,b) a ## b
-#define __cat(a,b) ___cat(a,b)
+#endif /* __MACH__ */
 
 #if __GNUC__ == 3 && __GNUC_MINOR__ < 3
 # define __used			__attribute__((__unused__))
@@ -60,13 +86,13 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
 
 /* Add a table entry.  We test function type matches while we're here. */
 #define ADD_TO_DEVTABLE(device_id, type, function) \
-	static struct devtable __cat(devtable,__LINE__) = {	\
+	static struct devtable __cat(devtable, __LINE__) = {	\
 		device_id + 0*sizeof((function)((const char *)NULL,	\
 						(type *)NULL,		\
 						(char *)NULL)),		\
 		sizeof(type), (function) };				\
-	static struct devtable *__attribute__((section("__devtable"))) \
-		__used __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
+	static struct devtable *SECTION(__devtable) __used \
+		__cat(devtable_ptr, __LINE__) = &__cat(devtable, __LINE__)
 
 #define ADD(str, sep, cond, field)                              \
 do {                                                            \
@@ -1080,6 +1106,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 		do_pnp_card_entries(symval, sym->st_size, mod);
 	else {
 		struct devtable **p;
+		INIT_SECTION(__devtable);
 
 		for (p = __start___devtable; p < __stop___devtable; p++) {
 			if (sym_is(name, namelen, (*p)->device_id)) {
-- 
1.7.9.1


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

* Re: [PATCH] mod/file2alias: make modpost compile on darwin again
  2012-02-22 21:55 [PATCH] mod/file2alias: make modpost compile on darwin again Andreas Bießmann
@ 2012-02-22 23:08 ` Rusty Russell
  2012-02-23  6:28   ` Andreas Bießmann
  2012-02-24  7:23 ` [PATCH v2] " Andreas Bießmann
  1 sibling, 1 reply; 8+ messages in thread
From: Rusty Russell @ 2012-02-22 23:08 UTC (permalink / raw)
  To: Andreas Bießmann, linux-kernel
  Cc: Andreas Bießmann, Greg Kroah-Hartman, Jochen Friedrich,
	Samuel Ortiz, K. Y. Srinivasan

On Wed, 22 Feb 2012 22:55:35 +0100, Andreas Bießmann <andreas@biessmann.de> wrote:
> commit e49ce14150c64b29a8dd211df785576fa19a9858 breaks cross compiling
> the linux kernel on darwin hosts.
> This fix introduce some minimal glue to adopt linker section handling
> for darwin hosts.

Really?

Yes, I assumed an ELF host.  There's a portable way of doing this, but
it's damn ugly (see http://ccodearchive.net/info/autodata.html).

Oh, and checkpatch.pl is wrong, the code was fine.

If noone has strong opinions about this, I'll apply it.  I'm a bit
weirded out though.

Thanks,
Rusty.

> Additionally this patch fixes minor chackpatch warnings introduced by
> mentioned commit.
> 
> Signed-off-by: Andreas Bießmann <andreas@biessmann.de>
> CC: Rusty Russell <rusty@rustcorp.com.au>
> CC: Greg Kroah-Hartman <gregkh@suse.de>
> CC: Jochen Friedrich <jochen@scram.de>
> CC: Samuel Ortiz <sameo@linux.intel.com>
> CC: "K. Y. Srinivasan" <kys@microsoft.com>
> ---
>  scripts/mod/file2alias.c |   37 ++++++++++++++++++++++++++++++++-----
>  1 files changed, 32 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> index d0de2a2..d2f42eb 100644
> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -46,11 +46,37 @@ struct devtable {
>  	void *function;
>  };
>  
> +#define ___cat(a, b) a ## b
> +#define __cat(a, b) ___cat(a, b)
> +
> +/* we need some special handling for this host tool running eventually on
> + * Darwin. The Mach-O section handling is a bit different than ELF section
> + * handling. The differnces in detail are:
> + *  a) we have segments which have sections
> + *  b) we need a API call to get the respective section symbols */
> +#if defined(__MACH__)
> +#include <mach-o/getsect.h>
> +
> +#define INIT_SECTION(name)  do {					\
> +		unsigned long name ## _len;				\
> +		char *__cat(pstart_, name) = getsectdata("__TEXT",	\
> +			#name, &__cat(name, _len));			\
> +		char *__cat(pstop_, name) = __cat(pstart_, name) +	\
> +			__cat(name, _len);				\
> +		__cat(__start_, name) = (void *)__cat(pstart_, name);	\
> +		__cat(__stop_, name) = (void *)__cat(pstop_, name);	\
> +	} while (0)
> +#define SECTION(name)   __attribute__((section("__TEXT, " #name)))
> +
> +struct devtable **__start___devtable, **__stop___devtable;
> +#else
> +#define INIT_SECTION(name) /* no-op for ELF */
> +#define SECTION(name)   __attribute__((section(#name)))
> +
>  /* We construct a table of pointers in an ELF section (pointers generally
>   * go unpadded by gcc).  ld creates boundary syms for us. */
>  extern struct devtable *__start___devtable[], *__stop___devtable[];
> -#define ___cat(a,b) a ## b
> -#define __cat(a,b) ___cat(a,b)
> +#endif /* __MACH__ */
>  
>  #if __GNUC__ == 3 && __GNUC_MINOR__ < 3
>  # define __used			__attribute__((__unused__))
> @@ -60,13 +86,13 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
>  
>  /* Add a table entry.  We test function type matches while we're here. */
>  #define ADD_TO_DEVTABLE(device_id, type, function) \
> -	static struct devtable __cat(devtable,__LINE__) = {	\
> +	static struct devtable __cat(devtable, __LINE__) = {	\
>  		device_id + 0*sizeof((function)((const char *)NULL,	\
>  						(type *)NULL,		\
>  						(char *)NULL)),		\
>  		sizeof(type), (function) };				\
> -	static struct devtable *__attribute__((section("__devtable"))) \
> -		__used __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
> +	static struct devtable *SECTION(__devtable) __used \
> +		__cat(devtable_ptr, __LINE__) = &__cat(devtable, __LINE__)
>  
>  #define ADD(str, sep, cond, field)                              \
>  do {                                                            \
> @@ -1080,6 +1106,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
>  		do_pnp_card_entries(symval, sym->st_size, mod);
>  	else {
>  		struct devtable **p;
> +		INIT_SECTION(__devtable);
>  
>  		for (p = __start___devtable; p < __stop___devtable; p++) {
>  			if (sym_is(name, namelen, (*p)->device_id)) {
> -- 
> 1.7.9.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

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

* Re: [PATCH] mod/file2alias: make modpost compile on darwin again
  2012-02-22 23:08 ` Rusty Russell
@ 2012-02-23  6:28   ` Andreas Bießmann
  2012-02-24  4:04     ` Rusty Russell
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Bießmann @ 2012-02-23  6:28 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Andreas Bießmann, linux-kernel, gregkh, Jochen Friedrich,
	Samuel Ortiz, K. Y. Srinivasan


On 23.02.12 00:08, Rusty Russell wrote:
> On Wed, 22 Feb 2012 22:55:35 +0100, Andreas Bießmann <andreas@biessmann.de> wrote:
>> commit e49ce14150c64b29a8dd211df785576fa19a9858 breaks cross compiling
>> the linux kernel on darwin hosts.
>> This fix introduce some minimal glue to adopt linker section handling
>> for darwin hosts.
> 
> Really?

Yes.

> Yes, I assumed an ELF host.  There's a portable way of doing this, but
> it's damn ugly (see http://ccodearchive.net/info/autodata.html).

I stumbled over some other code snippet [1] when searching for a solution.

> Oh, and checkpatch.pl is wrong, the code was fine.

Sorry for that. I was running checkpatch.pl as dutiful patch submitter
and that complained. Should I provide another version with 'checkpatch'
adoptions changed back?

> If noone has strong opinions about this, I'll apply it.

Would be great. I guess this is a rare case (cross compiling on darwin
host) but at least I and some of my colleagues do it from time to time.

Andreas
--
[1]
http://google-perftools.googlecode.com/svn/!svn/bc/48/trunk/src/base/basictypes.h

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

* Re: [PATCH] mod/file2alias: make modpost compile on darwin again
  2012-02-23  6:28   ` Andreas Bießmann
@ 2012-02-24  4:04     ` Rusty Russell
  0 siblings, 0 replies; 8+ messages in thread
From: Rusty Russell @ 2012-02-24  4:04 UTC (permalink / raw)
  To: Andreas Bießmann
  Cc: Andreas Bießmann, linux-kernel, gregkh, Jochen Friedrich,
	Samuel Ortiz, K. Y. Srinivasan

On Thu, 23 Feb 2012 07:28:41 +0100, Andreas Bießmann <andreas@biessmann.de> wrote:
> > Oh, and checkpatch.pl is wrong, the code was fine.
> 
> Sorry for that. I was running checkpatch.pl as dutiful patch submitter
> and that complained.

In the Olden Days, we could easily spot code which needed auditing
simply by looking at the (lack of) coding style.  But then someone
decided that the most important attribute of good code was the nature of
the whitespace within it.  And they wrote a tool.

For a while, this made it really hard for us maintainers to tell which
incoming patches we should actually read!  Fortunately, the
Anti-whitespace crusaders have come full circle: we can now tell newbie
coders by the fact that they obey checkpatch.pl.

> Should I provide another version with 'checkpatch' adoptions changed
> back?

Please :)

Thanks,
Rusty.

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

* [PATCH v2] mod/file2alias: make modpost compile on darwin again
  2012-02-22 21:55 [PATCH] mod/file2alias: make modpost compile on darwin again Andreas Bießmann
  2012-02-22 23:08 ` Rusty Russell
@ 2012-02-24  7:23 ` Andreas Bießmann
  2012-02-25  3:51   ` Rusty Russell
  2012-02-26 16:27   ` Bernhard Walle
  1 sibling, 2 replies; 8+ messages in thread
From: Andreas Bießmann @ 2012-02-24  7:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andreas Bießmann, Rusty Russell, Greg Kroah-Hartman,
	Jochen Friedrich, Samuel Ortiz, K. Y. Srinivasan

commit e49ce14150c64b29a8dd211df785576fa19a9858 breaks cross compiling
the linux kernel on darwin hosts.
This fix introduce some minimal glue to adopt linker section handling
for darwin hosts.

Signed-off-by: Andreas Bießmann <andreas@biessmann.de>
CC: Rusty Russell <rusty@rustcorp.com.au>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: Jochen Friedrich <jochen@scram.de>
CC: Samuel Ortiz <sameo@linux.intel.com>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
---
since v1:
 * change 'checkpatch' whitespace fixews back

 scripts/mod/file2alias.c |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index d0de2a2..b89efe6 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -46,11 +46,37 @@ struct devtable {
 	void *function;
 };
 
+#define ___cat(a,b) a ## b
+#define __cat(a,b) ___cat(a,b)
+
+/* we need some special handling for this host tool running eventually on
+ * Darwin. The Mach-O section handling is a bit different than ELF section
+ * handling. The differnces in detail are:
+ *  a) we have segments which have sections
+ *  b) we need a API call to get the respective section symbols */
+#if defined(__MACH__)
+#include <mach-o/getsect.h>
+
+#define INIT_SECTION(name)  do {					\
+		unsigned long name ## _len;				\
+		char *__cat(pstart_,name) = getsectdata("__TEXT",	\
+			#name, &__cat(name,_len));			\
+		char *__cat(pstop_,name) = __cat(pstart_,name) +	\
+			__cat(name, _len);				\
+		__cat(__start_,name) = (void *)__cat(pstart_,name);	\
+		__cat(__stop_,name) = (void *)__cat(pstop_,name);	\
+	} while (0)
+#define SECTION(name)   __attribute__((section("__TEXT, " #name)))
+
+struct devtable **__start___devtable, **__stop___devtable;
+#else
+#define INIT_SECTION(name) /* no-op for ELF */
+#define SECTION(name)   __attribute__((section(#name)))
+
 /* We construct a table of pointers in an ELF section (pointers generally
  * go unpadded by gcc).  ld creates boundary syms for us. */
 extern struct devtable *__start___devtable[], *__stop___devtable[];
-#define ___cat(a,b) a ## b
-#define __cat(a,b) ___cat(a,b)
+#endif /* __MACH__ */
 
 #if __GNUC__ == 3 && __GNUC_MINOR__ < 3
 # define __used			__attribute__((__unused__))
@@ -65,8 +91,8 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
 						(type *)NULL,		\
 						(char *)NULL)),		\
 		sizeof(type), (function) };				\
-	static struct devtable *__attribute__((section("__devtable"))) \
-		__used __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
+	static struct devtable *SECTION(__devtable) __used \
+		__cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
 
 #define ADD(str, sep, cond, field)                              \
 do {                                                            \
@@ -1080,6 +1106,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 		do_pnp_card_entries(symval, sym->st_size, mod);
 	else {
 		struct devtable **p;
+		INIT_SECTION(__devtable);
 
 		for (p = __start___devtable; p < __stop___devtable; p++) {
 			if (sym_is(name, namelen, (*p)->device_id)) {
-- 
1.7.9.1


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

* Re: [PATCH v2] mod/file2alias: make modpost compile on darwin again
  2012-02-24  7:23 ` [PATCH v2] " Andreas Bießmann
@ 2012-02-25  3:51   ` Rusty Russell
  2012-02-26 16:27   ` Bernhard Walle
  1 sibling, 0 replies; 8+ messages in thread
From: Rusty Russell @ 2012-02-25  3:51 UTC (permalink / raw)
  To: Andreas Bießmann, linux-kernel
  Cc: Andreas Bießmann, Greg Kroah-Hartman, Jochen Friedrich,
	Samuel Ortiz, K. Y. Srinivasan

On Fri, 24 Feb 2012 08:23:53 +0100, Andreas Bießmann <andreas@biessmann.de> wrote:
> commit e49ce14150c64b29a8dd211df785576fa19a9858 breaks cross compiling
> the linux kernel on darwin hosts.
> This fix introduce some minimal glue to adopt linker section handling
> for darwin hosts.

Thanks, applied.

Rusty.

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

* Re: [PATCH v2] mod/file2alias: make modpost compile on darwin again
  2012-02-24  7:23 ` [PATCH v2] " Andreas Bießmann
  2012-02-25  3:51   ` Rusty Russell
@ 2012-02-26 16:27   ` Bernhard Walle
  2012-02-27  0:03     ` [PULL] modpost fix for cross-compiling Rusty Russell
  1 sibling, 1 reply; 8+ messages in thread
From: Bernhard Walle @ 2012-02-26 16:27 UTC (permalink / raw)
  Cc: linux-kernel, Rusty Russell, Greg Kroah-Hartman,
	Jochen Friedrich, Samuel Ortiz, K. Y. Srinivasan,
	Andreas Bießmann

Hi,

Am 24.02.12 08:23, schrieb Andreas Bießmann:
> commit e49ce14150c64b29a8dd211df785576fa19a9858 breaks cross compiling
> the linux kernel on darwin hosts.
> This fix introduce some minimal glue to adopt linker section handling
> for darwin hosts.
> 
> Signed-off-by: Andreas Bießmann <andreas@biessmann.de>
> CC: Rusty Russell <rusty@rustcorp.com.au>
> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> CC: Jochen Friedrich <jochen@scram.de>
> CC: Samuel Ortiz <sameo@linux.intel.com>
> CC: "K. Y. Srinivasan" <kys@microsoft.com>

Tested-by: Bernhard Walle <bernhard@bwalle.de>

Would be nice if that patch gets applied even if cross-compiling the
Linux kernel on a Mac is exotic.


Regards,
Bernhard

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

* [PULL] modpost fix for cross-compiling
  2012-02-26 16:27   ` Bernhard Walle
@ 2012-02-27  0:03     ` Rusty Russell
  0 siblings, 0 replies; 8+ messages in thread
From: Rusty Russell @ 2012-02-27  0:03 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: linux-kernel, Greg Kroah-Hartman, Jochen Friedrich, Samuel Ortiz,
	K. Y. Srinivasan, Andreas Bießmann

To git@github.com:rustyrussell/linux.git
   0d86f65..dd2a3ac  master -> master
 + e45f03a...65e65f9 for-linus -> for-linus (forced update)
The following changes since commit 203738e548cefc3fc3c2f73a9063176c9f3583d5:

  Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net (2012-02-26 12:47:17 -0800)

are available in the git repository at:

  git://github.com/rustyrussell/linux.git master

Andreas Bießmann (1):
      mod/file2alias: make modpost compile on darwin again

 scripts/mod/file2alias.c |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)

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

end of thread, other threads:[~2012-02-27  0:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-22 21:55 [PATCH] mod/file2alias: make modpost compile on darwin again Andreas Bießmann
2012-02-22 23:08 ` Rusty Russell
2012-02-23  6:28   ` Andreas Bießmann
2012-02-24  4:04     ` Rusty Russell
2012-02-24  7:23 ` [PATCH v2] " Andreas Bießmann
2012-02-25  3:51   ` Rusty Russell
2012-02-26 16:27   ` Bernhard Walle
2012-02-27  0:03     ` [PULL] modpost fix for cross-compiling Rusty Russell

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 NNTP newsgroup(s).