xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Minios-devel <minios-devel@lists.xenproject.org>
Cc: Juergen Gross <jgross@suse.com>,
	Xen-devel <xen-devel@lists.xenproject.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Samuel Thibault <samuel.thibault@ens-lyon.org>
Subject: [MINIOS PATCH 3/3] x86: use unified linker script
Date: Thu, 18 Aug 2016 11:15:26 +0100	[thread overview]
Message-ID: <1471515326-4610-4-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1471515326-4610-1-git-send-email-wei.liu2@citrix.com>

There are only a few differences between i386 and x86-64 linker scripts.
Unify them into one. Re-indent the file at the same time.

Construct a special rule in top-level directory to cope with the change.
Ideally the build system should also be made more elegant, but
overhauling the build system is out of scope of this patch.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
v2:
1. fix one typo in code
2. use single-parameter form of OUTPUT_FORMAT
---
 .gitignore                 |   1 +
 Makefile                   |   6 +-
 arch/x86/Makefile          |   1 +
 arch/x86/minios-x86.lds.S  | 133 +++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/minios-x86_32.lds |  78 --------------------------
 arch/x86/minios-x86_64.lds |  78 --------------------------
 6 files changed, 140 insertions(+), 157 deletions(-)
 create mode 100644 arch/x86/minios-x86.lds.S
 delete mode 100644 arch/x86/minios-x86_32.lds
 delete mode 100644 arch/x86/minios-x86_64.lds

diff --git a/.gitignore b/.gitignore
index f21cc46..efc193c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 *.o
 *.a
 *.swp
+arch/x86/minios-x86*.lds
 include/list.h
 mini-os
 mini-os.gz
diff --git a/Makefile b/Makefile
index 5464e89..779bc91 100644
--- a/Makefile
+++ b/Makefile
@@ -148,7 +148,11 @@ ifneq ($(APP_OBJS),)
 APP_O=$(OBJ_DIR)/$(TARGET)_app.o 
 endif
 
-$(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib
+# Special rule for x86 for now
+arch/x86/minios-x86%.lds:  arch/x86/minios-x86.lds.S
+	$(CPP) $(ASFLAGS) -P $< -o $@
+
+$(OBJ_DIR)/$(TARGET): $(OBJS) $(APP_O) arch_lib $(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
 	$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o $@.o
 	$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o
 	$(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 0052b4c..dbe9ca6 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -24,4 +24,5 @@ $(OBJ_DIR)/$(ARCH_LIB): $(ARCH_OBJS) $(OBJ_DIR)/$(HEAD_ARCH_OBJ)
 
 clean:
 	rm -f $(OBJ_DIR)/$(ARCH_LIB) $(ARCH_OBJS) $(OBJ_DIR)/$(HEAD_ARCH_OBJ)
+	rm -f minios-x86_32.lds minios-x86_64.lds
 
diff --git a/arch/x86/minios-x86.lds.S b/arch/x86/minios-x86.lds.S
new file mode 100644
index 0000000..8aae2fd
--- /dev/null
+++ b/arch/x86/minios-x86.lds.S
@@ -0,0 +1,133 @@
+#if defined(__x86_64__)
+
+OUTPUT_FORMAT("elf64-x86-64")
+OUTPUT_ARCH(i386:x86-64)
+
+#elif defined(__i386__)
+#undef i386
+OUTPUT_FORMAT("elf32-i386")
+OUTPUT_ARCH(i386)
+
+#else
+# error Bad architecture to link with
+#endif
+
+ENTRY(_start)
+SECTIONS
+{
+        . = 0x0;
+        _text = .;			/* Text and read-only data */
+        .text : {
+                *(.text)
+                *(.gnu.warning)
+        } = 0x9090
+
+        _etext = .;			/* End of text section */
+
+        .rodata : {
+                *(.rodata)
+                *(.rodata.*)
+        }
+        . = ALIGN(4096);
+        _erodata = .;
+
+        .note : {
+                *(.note)
+                *(.note.*)
+        }
+
+        /* newlib initialization functions */
+#if defined(__x86_64__)
+        . = ALIGN(64 / 8);
+#else /* __i386 __ */
+        . = ALIGN(32 / 8);
+#endif
+        PROVIDE (__preinit_array_start = .);
+        .preinit_array : {
+                *(.preinit_array)
+        }
+        PROVIDE (__preinit_array_end = .);
+        PROVIDE (__init_array_start = .);
+        .init_array : {
+                *(.init_array)
+        }
+        PROVIDE (__init_array_end = .);
+        PROVIDE (__fini_array_start = .);
+        .fini_array : {
+                *(.fini_array)
+        }
+        PROVIDE (__fini_array_end = .);
+
+        .ctors : {
+                __CTOR_LIST__ = .;
+                *(.ctors)
+                CONSTRUCTORS
+#if defined(__x86_64__)
+                QUAD(0)
+#else /* __i386__ */
+                LONG(0)
+#endif
+                __CTOR_END__ = .;
+        }
+
+        .dtors : {
+                __DTOR_LIST__ = .;
+                *(.dtors)
+#if defined(__x86_64__)
+                QUAD(0)
+#else /* __i386__ */
+                LONG(0)
+#endif
+                __DTOR_END__ = .;
+        }
+
+        .data : {			/* Data */
+                *(.data)
+        }
+
+        _edata = .;			/* End of data section */
+
+        __bss_start = .;		/* BSS */
+        .bss : {
+                *(.bss)
+                *(.app.bss)
+        }
+        _end = . ;
+
+        /* Sections to be discarded */
+        /DISCARD/ : {
+                *(.text.exit)
+                *(.data.exit)
+                *(.exitcall.exit)
+        }
+
+        /* Stabs debugging sections.  */
+        .stab 0 : {
+                *(.stab)
+        }
+        .stabstr 0 : {
+                *(.stabstr)
+        }
+        .stab.excl 0 : {
+                *(.stab.excl)
+        }
+        .stab.exclstr 0 : {
+                *(.stab.exclstr)
+        }
+        .stab.index 0 : {
+                *(.stab.index)
+        }
+        .stab.indexstr 0 : {
+                *(.stab.indexstr)
+        }
+        .comment 0 : {
+                *(.comment)
+        }
+}
+
+/*
+ * Local variables:
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/arch/x86/minios-x86_32.lds b/arch/x86/minios-x86_32.lds
deleted file mode 100644
index e4e18cb..0000000
--- a/arch/x86/minios-x86_32.lds
+++ /dev/null
@@ -1,78 +0,0 @@
-OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
-OUTPUT_ARCH(i386)
-ENTRY(_start)
-SECTIONS
-{
-  . = 0x0;
-  _text = .;			/* Text and read-only data */
-  .text : {
-	*(.text)
-	*(.gnu.warning)
-	} = 0x9090
-
-  _etext = .;			/* End of text section */
-
-  .rodata : { *(.rodata) *(.rodata.*) }
-  . = ALIGN(4096);
-  _erodata = .;
-  .note : {
-	*(.note)
-	*(.note.*)
-  }
-
-  /* newlib initialization functions */
-  . = ALIGN(32 / 8);
-  PROVIDE (__preinit_array_start = .);
-  .preinit_array     : { *(.preinit_array) }
-  PROVIDE (__preinit_array_end = .);
-  PROVIDE (__init_array_start = .);
-  .init_array     : { *(.init_array) }
-  PROVIDE (__init_array_end = .);
-  PROVIDE (__fini_array_start = .);
-  .fini_array     : { *(.fini_array) }
-  PROVIDE (__fini_array_end = .);
-
-  .ctors : {
-        __CTOR_LIST__ = .;
-        *(.ctors)
-	CONSTRUCTORS
-        LONG(0)
-        __CTOR_END__ = .;
-        }
-
-  .dtors : {
-        __DTOR_LIST__ = .;
-        *(.dtors)
-        LONG(0)
-        __DTOR_END__ = .;
-        }
-
-  .data : {			/* Data */
-	*(.data)
-	}
-
-  _edata = .;			/* End of data section */
-
-  __bss_start = .;		/* BSS */
-  .bss : {
-	*(.bss)
-        *(.app.bss)
-	}
-  _end = . ;
-
-  /* Sections to be discarded */
-  /DISCARD/ : {
-	*(.text.exit)
-	*(.data.exit)
-	*(.exitcall.exit)
-	}
-
-  /* Stabs debugging sections.  */
-  .stab 0 : { *(.stab) }
-  .stabstr 0 : { *(.stabstr) }
-  .stab.excl 0 : { *(.stab.excl) }
-  .stab.exclstr 0 : { *(.stab.exclstr) }
-  .stab.index 0 : { *(.stab.index) }
-  .stab.indexstr 0 : { *(.stab.indexstr) }
-  .comment 0 : { *(.comment) }
-}
diff --git a/arch/x86/minios-x86_64.lds b/arch/x86/minios-x86_64.lds
deleted file mode 100644
index f6462f3..0000000
--- a/arch/x86/minios-x86_64.lds
+++ /dev/null
@@ -1,78 +0,0 @@
-OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
-OUTPUT_ARCH(i386:x86-64)
-ENTRY(_start)
-SECTIONS
-{
-  . = 0x0;
-  _text = .;			/* Text and read-only data */
-  .text : {
-	*(.text)
-	*(.gnu.warning)
-	} = 0x9090
-
-  _etext = .;			/* End of text section */
-
-  .rodata : { *(.rodata) *(.rodata.*) }
-  . = ALIGN(4096);
-  _erodata = .;
-  .note : {
-	*(.note)
-	*(.note.*)
-  }
-
-  /* newlib initialization functions */
-  . = ALIGN(64 / 8);
-  PROVIDE (__preinit_array_start = .);
-  .preinit_array     : { *(.preinit_array) }
-  PROVIDE (__preinit_array_end = .);
-  PROVIDE (__init_array_start = .);
-  .init_array     : { *(.init_array) }
-  PROVIDE (__init_array_end = .);
-  PROVIDE (__fini_array_start = .);
-  .fini_array     : { *(.fini_array) }
-  PROVIDE (__fini_array_end = .);
-
-  .ctors : {
-        __CTOR_LIST__ = .;
-        *(.ctors)
-	CONSTRUCTORS
-        QUAD(0)
-        __CTOR_END__ = .;
-        }
-
-  .dtors : {
-        __DTOR_LIST__ = .;
-        *(.dtors)
-        QUAD(0)
-        __DTOR_END__ = .;
-        }
-
-  .data : {			/* Data */
-	*(.data)
-	}
-
-  _edata = .;			/* End of data section */
-
-  __bss_start = .;		/* BSS */
-  .bss : {
-	*(.bss)
-        *(.app.bss)
-	}
-  _end = . ;
-
-  /* Sections to be discarded */
-  /DISCARD/ : {
-	*(.text.exit)
-	*(.data.exit)
-	*(.exitcall.exit)
-	}
-
-  /* Stabs debugging sections.  */
-  .stab 0 : { *(.stab) }
-  .stabstr 0 : { *(.stabstr) }
-  .stab.excl 0 : { *(.stab.excl) }
-  .stab.exclstr 0 : { *(.stab.exclstr) }
-  .stab.index 0 : { *(.stab.index) }
-  .stab.indexstr 0 : { *(.stab.indexstr) }
-  .comment 0 : { *(.comment) }
-}
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-08-18 10:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 10:15 [MINIOS PATCH 0/3] x86: use ELF notes and unified linker script Wei Liu
2016-08-18 10:15 ` [MINIOS PATCH 1/3] Introduce asm_macros.h Wei Liu
2016-08-18 10:34   ` Juergen Gross
2016-08-20 11:03     ` Samuel Thibault
2016-08-18 10:15 ` [MINIOS PATCH 2/3] x86: switch to use elfnote Wei Liu
2016-08-20 11:04   ` Samuel Thibault
2016-08-18 10:15 ` Wei Liu [this message]
2016-08-18 10:39   ` [MINIOS PATCH 3/3] x86: use unified linker script Juergen Gross
2016-08-20 11:05     ` Samuel Thibault
2016-08-18 10:20 ` [MINIOS PATCH 0/3] x86: use ELF notes and " Andrew Cooper
2016-08-22  9:41 ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471515326-4610-4-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=jgross@suse.com \
    --cc=minios-devel@lists.xenproject.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).