[PATCH] Translate asm version of ELFNOTE macro into preprocessor macro

STALE7282d

4 messages, 2 authors, 2006-08-23 · open the first message on its own page

[PATCH] Translate asm version of ELFNOTE macro into preprocessor macro

From: Ian Campbell <hidden>
Date: 2006-08-23 11:49:19

Hi,

I've come across some problems with the assembly version of the ELFNOTE
macro currently in -mm. (in
x86-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch)

The first is that older gas does not support :varargs in .macro
definitions (in my testing 2.17 does while 2.15 does not, I don't know
when it became supported). The Changes file says binutils >= 2.12 so I
think we need to avoid using it. There are no other uses in mainline or
-mm. Old gas appears to just ignore it so you get "too many arguments"
type errors.

Secondly it seems that passing strings as arguments to assembler macros
is broken without varargs. It looks like they get unquoted or each
character is treated as a separate argument or something and this causes
all manner of grief. I think this is because of the use of -traditional
when compiling assembly files.

Therefore I have translated the assembler macro into a pre-processor
macro.

I added the desctype as a separate argument instead of including it with
the descdata as the previous version did since -traditional means the
ELFNOTE definition after the #else needs to have the same number of
arguments (I think so anyway, the -traditional CPP semantics are pretty
fscking strange!).

With this patch I am able to define elfnotes in assembly like this with
both old and new assemblers.

	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS,       .asciz, "linux")	
	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_VERSION,  .asciz, "2.6")
	ELFNOTE(Xen, XEN_ELFNOTE_XEN_VERSION,    .asciz, "xen-3.0")
	ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE,      .long,  __PAGE_OFFSET)

Which seems reasonable enough.

Signed-off-by: Ian Campbell <redacted>

diff -r 4b7cd997c08f include/linux/elfnote.h
--- a/include/linux/elfnote.h	Wed Aug 23 11:48:46 2006 +0100
+++ b/include/linux/elfnote.h	Wed Aug 23 12:44:27 2006 +0100
@@ -31,22 +31,24 @@
 /*
  * Generate a structure with the same shape as Elf{32,64}_Nhdr (which
  * turn out to be the same size and shape), followed by the name and
- * desc data with appropriate padding.  The 'desc' argument includes
- * the assembler pseudo op defining the type of the data: .asciz
- * "hello, world"
+ * desc data with appropriate padding.  The 'desctype' argument is the
+ * assembler pseudo op defining the type of the data e.g. .asciz while
+ * 'descdata' is the data itself e.g.  "hello, world".
+ *
+ * e.g. ELFNOTE(XYZCo, 42, .asciz, "forty-two")
+ *      ELFNOTE(XYZCo, 12, .long, 0xdeadbeef)
  */
-.macro ELFNOTE name type desc:vararg
-.pushsection ".note.\name"
-  .align 4
-  .long 2f - 1f			/* namesz */
-  .long 4f - 3f			/* descsz */
-  .long \type
-1:.asciz "\name"
-2:.align 4
-3:\desc
-4:.align 4
-.popsection
-.endm
+#define ELFNOTE(name, type, desctype, descdata)	\
+.pushsection .note.name			;	\
+  .align 4				;	\
+  .long 2f - 1f		/* namesz */	;	\
+  .long 4f - 3f		/* descsz */	;	\
+  .long type				;	\
+1:.asciz "name"				;	\
+2:.align 4				;	\
+3:desctype descdata			;	\
+4:.align 4				;	\
+.popsection				;
 #else	/* !__ASSEMBLER__ */
 #include <linux/elf.h>
 /*

Re: [PATCH] Translate asm version of ELFNOTE macro into preprocessor macro

From: Jeremy Fitzhardinge <hidden>
Date: 2006-08-23 14:49:56

Ian Campbell wrote:
The first is that older gas does not support :varargs in .macro
definitions (in my testing 2.17 does while 2.15 does not, I don't know
when it became supported). The Changes file says binutils >= 2.12 so I
think we need to avoid using it. There are no other uses in mainline or
-mm. Old gas appears to just ignore it so you get "too many arguments"
type errors.
  
OK, seems reasonable.  Eric Biederman solved this by having NOTE/ENDNOTE 
(or something like that) in his "bzImage with ELF header" patch, but I 
don't remember it being used in any way which is incompatible with using 
a CPP macro.

Signed-off-by: Jeremy Fitzhardinge <redacted>

    J

Re: [PATCH] Translate asm version of ELFNOTE macro into preprocessor macro

From: Ian Campbell <hidden>
Date: 2006-08-23 15:14:32

On Wed, 2006-08-23 at 07:49 -0700, Jeremy Fitzhardinge wrote:
Ian Campbell wrote:
quoted
The first is that older gas does not support :varargs in .macro
definitions (in my testing 2.17 does while 2.15 does not, I don't know
when it became supported). The Changes file says binutils >= 2.12 so I
think we need to avoid using it. There are no other uses in mainline or
-mm. Old gas appears to just ignore it so you get "too many arguments"
type errors.
  
OK, seems reasonable.  Eric Biederman solved this by having NOTE/ENDNOTE 
(or something like that) in his "bzImage with ELF header" patch, but I 
don't remember it being used in any way which is incompatible with using 
a CPP macro.
I can't find that patch, does NOTE/ENDNOTE just do the push/pop .note
section?

That would solve the problem with the first argument of the macro being
a string but the final argument could still be for .asciz note contents.

Ian.

Re: [PATCH] Translate asm version of ELFNOTE macro into preprocessor macro

From: Jeremy Fitzhardinge <hidden>
Date: 2006-08-23 15:23:33

Ian Campbell wrote:
quoted
OK, seems reasonable.  Eric Biederman solved this by having NOTE/ENDNOTE 
(or something like that) in his "bzImage with ELF header" patch, but I 
don't remember it being used in any way which is incompatible with using 
a CPP macro.
    
I can't find that patch, does NOTE/ENDNOTE just do the push/pop .note
section?

That would solve the problem with the first argument of the macro being
a string but the final argument could still be for .asciz note contents.
  
It looks like:

.macro note name, type
      .balign 4
      .int    2f - 1f            # n_namesz
      .int    4f - 3f            # n_descsz
      .int    \type            # n_type
      .balign 4
1:    .asciz "\name"
2:    .balign 4
3:
.endm
.macro enote
4:    .balign 4
.endm


so it allows you to put arbitrary stuff in the desc part of the note.  
The downside is that its a little more cumbersome syntactically for the 
common case.

    J
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help