[RFC,02/11] elf: add macro to define note section for LibOS
diff mbox series

Message ID 3a8a966bae935849c4d4f2116c181c0156fb40ca.1568219399.git.isaku.yamahata@gmail.com
State New
Headers show
Series
  • Library OS support
Related show

Commit Message

Isaku Yamahata Sept. 11, 2019, 9:04 p.m. UTC
This patch defines macro to define note section for LibOS.
Later patches will use those macros.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
---
 elf/libos.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 elf/libos.h

Patch
diff mbox series

diff --git a/elf/libos.h b/elf/libos.h
new file mode 100644
index 0000000000..0610c212ff
--- /dev/null
+++ b/elf/libos.h
@@ -0,0 +1,84 @@ 
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _LIBOS_H
+#define _LIBOS_H    1
+
+#include <link.h>
+
+#define STRINGIFY(name) STRINGIFY_1(name)
+#define STRINGIFY_1(name)   #name
+
+#define NT_LIBOS    0x4f62694c    /* "LibO" in little endian */
+#define ELF_NOTE_LIBOS  "LibOS"
+#define LIBOS_NOTE_VERSION  1
+#define LIBOS_NOTE_FUNCTION 2
+#define LIBOS_NOTE_VARIABLE 3
+
+struct libos_note_desc {
+    ElfW(Word) name_sz;
+    ElfW(Word) type;
+    ElfW(Addr) ptr;
+    ElfW(Word) sz;
+    /* name */
+};
+
+#if __SIZEOF_PTRDIFF_T__  == 8
+#define LIBOS_NOTES(n_name, type, ptr, sz, name)                \
+    __asm__ (                                                   \
+        "   .pushsection .note.libos." n_name ",\"a\",@note\n"  \
+        "   .balign 8\n"                                        \
+        "   .long 1f - 0f\n"    /* name length */               \
+        "   .long 5f - 2f\n"    /* desc size */                 \
+        "   .long " STRINGIFY(NT_LIBOS) "\n"  /* note type*/    \
+        "0: .asciz \"libos\"\n"                                 \
+        "1:\n"                                                  \
+        "   .balign 8\n"                                        \
+        "2:\n"                                                  \
+        "   .long 4f - 3f\n"                                    \
+        "   .long " STRINGIFY(type) "\n"                        \
+        "   .quad " STRINGIFY(ptr) "\n"                         \
+        "   .quad " STRINGIFY(sz) "\n"                          \
+        "3: .asciz \"" name "\"\n"                              \
+        "4:\n"                                                  \
+        "   .balign 8\n"                                        \
+        "5:\n"                                                  \
+        "   .popsection\n")
+#elif __SIZEOF_PTRDIFF_T__  == 4
+#define LIBOS_NOTES(n_name, type, ptr, sz, name)                \
+    __asm__ (                                                   \
+        "   .pushsection .note.libos." n_name ",\"a\",@note\n"  \
+        "   .balign 4\n"                                        \
+        "   .long 1f - 0f\n"    /* name length */               \
+        "   .long 5f - 2f\n"    /* desc size */                 \
+        "   .long " STRINGIFY(NT_LIBOS) "\n"  /* note type*/    \
+        "0: .asciz \"libos\"\n"                                 \
+        "1:\n"                                                  \
+        "   .balign 4\n"                                        \
+        "2:\n"                                                  \
+        "   .long 4f - 3f\n"                                    \
+        "   .long " STRINGIFY(type) "\n"                        \
+        "   .long " STRINGIFY(ptr) "\n"                         \
+        "   .long " STRINGIFY(sz) "\n"                          \
+        "3: .asciz \"" name "\"\n"                              \
+        "4:\n"                                                  \
+        "   .balign 4\n"                                        \
+        "5:\n"                                                  \
+        "   .popsection\n")
+#endif
+
+#endif /* libos.h */