David Vrabel
2013-Sep-12 20:00 UTC
[PATCH 1/5] purgatory: put variables altered by kexec in .data not .bss
From: David Vrabel <david.vrabel@citrix.com> elf_rel_set_symbol() fails if the symbol is in the .bss section. Signed-off-by: David Vrabel <david.vrabel@citrix.com> --- purgatory/arch/i386/console-x86.c | 6 +++--- purgatory/arch/i386/crashdump_backup.c | 8 +++++--- purgatory/arch/x86_64/purgatory-x86_64.c | 6 +++--- purgatory/include/purgatory.h | 4 ++++ purgatory/purgatory.c | 4 ++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/purgatory/arch/i386/console-x86.c b/purgatory/arch/i386/console-x86.c index 9773573..40a734b 100644 --- a/purgatory/arch/i386/console-x86.c +++ b/purgatory/arch/i386/console-x86.c @@ -55,9 +55,9 @@ static void putchar_vga(int ch) */ /* Base Address */ -uint8_t console_serial = 0; -uint16_t serial_base = 0x3f8; /* TTYS0 */ -uint32_t serial_baud = 0; +uint8_t console_serial __data = 0; +uint16_t serial_base __data = 0x3f8; /* TTYS0 */ +uint32_t serial_baud __data = 0; #define XMTRDY 0x20 diff --git a/purgatory/arch/i386/crashdump_backup.c b/purgatory/arch/i386/crashdump_backup.c index 365eb5d..0438a75 100644 --- a/purgatory/arch/i386/crashdump_backup.c +++ b/purgatory/arch/i386/crashdump_backup.c @@ -21,13 +21,15 @@ #include <stdint.h> #include <string.h> +#include <purgatory.h> + /* Backup region start gets set after /proc/iomem has been parsed. */ /* We reuse the same code for x86_64 also so changing backup_start to unsigned long */ -unsigned long backup_start = 0; +unsigned long backup_start __data = 0; -unsigned long backup_src_start = 0; -unsigned long backup_src_size = 0; +unsigned long backup_src_start __data = 0; +unsigned long backup_src_size __data = 0; /* Backup first 640K of memory to backup region as reserved by kexec. * Assuming first 640K has to be present on i386 machines and no address diff --git a/purgatory/arch/x86_64/purgatory-x86_64.c b/purgatory/arch/x86_64/purgatory-x86_64.c index c25a9c2..8a3e24d 100644 --- a/purgatory/arch/x86_64/purgatory-x86_64.c +++ b/purgatory/arch/x86_64/purgatory-x86_64.c @@ -3,11 +3,11 @@ #include <purgatory.h> #include "purgatory-x86_64.h" -uint8_t reset_vga = 0; +uint8_t reset_vga __data = 0; uint8_t legacy_pic = 0; -uint8_t panic_kernel = 0; +uint8_t panic_kernel __data = 0; unsigned long jump_back_entry = 0; -char *cmdline_end = NULL; +char *cmdline_end __data = NULL; void setup_arch(void) { diff --git a/purgatory/include/purgatory.h b/purgatory/include/purgatory.h index ed50dc4..e2b061a 100644 --- a/purgatory/include/purgatory.h +++ b/purgatory/include/purgatory.h @@ -1,6 +1,10 @@ #ifndef PURGATORY_H #define PURGATORY_H +/* Force variables that are adjusted by kexec to be in .data not + .bss. */ +#define __data __attribute__((section("data"))) + void putchar(int ch); void sprintf(char *buffer, const char *fmt, ...); void printf(const char *fmt, ...); diff --git a/purgatory/purgatory.c b/purgatory/purgatory.c index 3bbcc09..05f3b48 100644 --- a/purgatory/purgatory.c +++ b/purgatory/purgatory.c @@ -6,8 +6,8 @@ #include <string.h> #include "../kexec/kexec-sha256.h" -struct sha256_region sha256_regions[SHA256_REGIONS] = {}; -sha256_digest_t sha256_digest = { }; +struct sha256_region sha256_regions[SHA256_REGIONS] __data = {}; +sha256_digest_t sha256_digest __data = { }; int verify_sha256_digest(void) { -- 1.7.2.5
Daniel Kiper
2013-Sep-16 12:43 UTC
Re: [PATCH 1/5] purgatory: put variables altered by kexec in .data not .bss
On Thu, Sep 12, 2013 at 09:00:38PM +0100, David Vrabel wrote:> From: David Vrabel <david.vrabel@citrix.com> > > elf_rel_set_symbol() fails if the symbol is in the .bss section. > > Signed-off-by: David Vrabel <david.vrabel@citrix.com> > --- > purgatory/arch/i386/console-x86.c | 6 +++--- > purgatory/arch/i386/crashdump_backup.c | 8 +++++--- > purgatory/arch/x86_64/purgatory-x86_64.c | 6 +++--- > purgatory/include/purgatory.h | 4 ++++ > purgatory/purgatory.c | 4 ++-- > 5 files changed, 17 insertions(+), 11 deletions(-) > > diff --git a/purgatory/arch/i386/console-x86.c b/purgatory/arch/i386/console-x86.c > index 9773573..40a734b 100644 > --- a/purgatory/arch/i386/console-x86.c > +++ b/purgatory/arch/i386/console-x86.c > @@ -55,9 +55,9 @@ static void putchar_vga(int ch) > */ > > /* Base Address */ > -uint8_t console_serial = 0; > -uint16_t serial_base = 0x3f8; /* TTYS0 */ > -uint32_t serial_baud = 0; > +uint8_t console_serial __data = 0; > +uint16_t serial_base __data = 0x3f8; /* TTYS0 */ > +uint32_t serial_baud __data = 0;Hmmm... I do not know why we need this patch. I can build kexec-tools in my env without it. I suppose that most of people can too. Could you check what is wrong with your build system? Daniel
David Vrabel
2013-Sep-16 12:48 UTC
Re: [PATCH 1/5] purgatory: put variables altered by kexec in .data not .bss
On 16/09/13 13:43, Daniel Kiper wrote:> On Thu, Sep 12, 2013 at 09:00:38PM +0100, David Vrabel wrote: >> From: David Vrabel <david.vrabel@citrix.com> >> >> elf_rel_set_symbol() fails if the symbol is in the .bss section. >> >> Signed-off-by: David Vrabel <david.vrabel@citrix.com> >> --- >> purgatory/arch/i386/console-x86.c | 6 +++--- >> purgatory/arch/i386/crashdump_backup.c | 8 +++++--- >> purgatory/arch/x86_64/purgatory-x86_64.c | 6 +++--- >> purgatory/include/purgatory.h | 4 ++++ >> purgatory/purgatory.c | 4 ++-- >> 5 files changed, 17 insertions(+), 11 deletions(-) >> >> diff --git a/purgatory/arch/i386/console-x86.c b/purgatory/arch/i386/console-x86.c >> index 9773573..40a734b 100644 >> --- a/purgatory/arch/i386/console-x86.c >> +++ b/purgatory/arch/i386/console-x86.c >> @@ -55,9 +55,9 @@ static void putchar_vga(int ch) >> */ >> >> /* Base Address */ >> -uint8_t console_serial = 0; >> -uint16_t serial_base = 0x3f8; /* TTYS0 */ >> -uint32_t serial_baud = 0; >> +uint8_t console_serial __data = 0; >> +uint16_t serial_base __data = 0x3f8; /* TTYS0 */ >> +uint32_t serial_baud __data = 0; > > Hmmm... I do not know why we need this patch. I can build kexec-tools > in my env without it. I suppose that most of people can too. > Could you check what is wrong with your build system?Regardless of whether it works with some tools, it doesn''t make a whole lot of sense to try and set the value of symbols in the .bss section. .bss is only for symbols with a value of zero. David
Daniel Kiper
2013-Sep-17 01:33 UTC
Re: [PATCH 1/5] purgatory: put variables altered by kexec in .data not .bss
On Mon, Sep 16, 2013 at 01:48:07PM +0100, David Vrabel wrote:> On 16/09/13 13:43, Daniel Kiper wrote: > > On Thu, Sep 12, 2013 at 09:00:38PM +0100, David Vrabel wrote: > >> From: David Vrabel <david.vrabel@citrix.com> > >> > >> elf_rel_set_symbol() fails if the symbol is in the .bss section. > >> > >> Signed-off-by: David Vrabel <david.vrabel@citrix.com> > >> --- > >> purgatory/arch/i386/console-x86.c | 6 +++--- > >> purgatory/arch/i386/crashdump_backup.c | 8 +++++--- > >> purgatory/arch/x86_64/purgatory-x86_64.c | 6 +++--- > >> purgatory/include/purgatory.h | 4 ++++ > >> purgatory/purgatory.c | 4 ++-- > >> 5 files changed, 17 insertions(+), 11 deletions(-) > >> > >> diff --git a/purgatory/arch/i386/console-x86.c b/purgatory/arch/i386/console-x86.c > >> index 9773573..40a734b 100644 > >> --- a/purgatory/arch/i386/console-x86.c > >> +++ b/purgatory/arch/i386/console-x86.c > >> @@ -55,9 +55,9 @@ static void putchar_vga(int ch) > >> */ > >> > >> /* Base Address */ > >> -uint8_t console_serial = 0; > >> -uint16_t serial_base = 0x3f8; /* TTYS0 */ > >> -uint32_t serial_baud = 0; > >> +uint8_t console_serial __data = 0; > >> +uint16_t serial_base __data = 0x3f8; /* TTYS0 */ > >> +uint32_t serial_baud __data = 0; > > > > Hmmm... I do not know why we need this patch. I can build kexec-tools > > in my env without it. I suppose that most of people can too. > > Could you check what is wrong with your build system? > > Regardless of whether it works with some tools, it doesn''t make a whole > lot of sense to try and set the value of symbols in the .bss section. > .bss is only for symbols with a value of zero.To be precise .bss is only for uninitialized symbols. Anyway, probably your compiler is screwed. In my case it sees that a given symbol is initialized and places it in .data section itself. Daniel
Tim Deegan
2013-Sep-17 08:17 UTC
Re: [PATCH 1/5] purgatory: put variables altered by kexec in .data not .bss
At 03:33 +0200 on 17 Sep (1379388789), Daniel Kiper wrote:> On Mon, Sep 16, 2013 at 01:48:07PM +0100, David Vrabel wrote: > > On 16/09/13 13:43, Daniel Kiper wrote: > > > On Thu, Sep 12, 2013 at 09:00:38PM +0100, David Vrabel wrote: > > >> From: David Vrabel <david.vrabel@citrix.com> > > >> > > >> elf_rel_set_symbol() fails if the symbol is in the .bss section. > > >> > > >> Signed-off-by: David Vrabel <david.vrabel@citrix.com> > > >> --- > > >> purgatory/arch/i386/console-x86.c | 6 +++--- > > >> purgatory/arch/i386/crashdump_backup.c | 8 +++++--- > > >> purgatory/arch/x86_64/purgatory-x86_64.c | 6 +++--- > > >> purgatory/include/purgatory.h | 4 ++++ > > >> purgatory/purgatory.c | 4 ++-- > > >> 5 files changed, 17 insertions(+), 11 deletions(-) > > >> > > >> diff --git a/purgatory/arch/i386/console-x86.c b/purgatory/arch/i386/console-x86.c > > >> index 9773573..40a734b 100644 > > >> --- a/purgatory/arch/i386/console-x86.c > > >> +++ b/purgatory/arch/i386/console-x86.c > > >> @@ -55,9 +55,9 @@ static void putchar_vga(int ch) > > >> */ > > >> > > >> /* Base Address */ > > >> -uint8_t console_serial = 0; > > >> -uint16_t serial_base = 0x3f8; /* TTYS0 */ > > >> -uint32_t serial_baud = 0; > > >> +uint8_t console_serial __data = 0; > > >> +uint16_t serial_base __data = 0x3f8; /* TTYS0 */ > > >> +uint32_t serial_baud __data = 0; > > > > > > Hmmm... I do not know why we need this patch. I can build kexec-tools > > > in my env without it. I suppose that most of people can too. > > > Could you check what is wrong with your build system? > > > > Regardless of whether it works with some tools, it doesn''t make a whole > > lot of sense to try and set the value of symbols in the .bss section. > > .bss is only for symbols with a value of zero. > > To be precise .bss is only for uninitialized symbols. Anyway, probably > your compiler is screwed. In my case it sees that a given symbol is > initialized and places it in .data section itself.David, are you using a compiler that doesn''t support -fno-zero-initialized-in-bss? If that''s a supported optoin, then the __data markers are indeed necessary. Tim.
David Vrabel
2013-Sep-17 09:59 UTC
Re: [PATCH 1/5] purgatory: put variables altered by kexec in .data not .bss
On 17/09/13 09:17, Tim Deegan wrote:> At 03:33 +0200 on 17 Sep (1379388789), Daniel Kiper wrote: >> On Mon, Sep 16, 2013 at 01:48:07PM +0100, David Vrabel wrote: >>> On 16/09/13 13:43, Daniel Kiper wrote: >>>> On Thu, Sep 12, 2013 at 09:00:38PM +0100, David Vrabel wrote: >>>>> From: David Vrabel <david.vrabel@citrix.com> >>>>> >>>>> elf_rel_set_symbol() fails if the symbol is in the .bss section. >>>>> >>>>> Signed-off-by: David Vrabel <david.vrabel@citrix.com> >>>>> --- >>>>> purgatory/arch/i386/console-x86.c | 6 +++--- >>>>> purgatory/arch/i386/crashdump_backup.c | 8 +++++--- >>>>> purgatory/arch/x86_64/purgatory-x86_64.c | 6 +++--- >>>>> purgatory/include/purgatory.h | 4 ++++ >>>>> purgatory/purgatory.c | 4 ++-- >>>>> 5 files changed, 17 insertions(+), 11 deletions(-) >>>>> >>>>> diff --git a/purgatory/arch/i386/console-x86.c b/purgatory/arch/i386/console-x86.c >>>>> index 9773573..40a734b 100644 >>>>> --- a/purgatory/arch/i386/console-x86.c >>>>> +++ b/purgatory/arch/i386/console-x86.c >>>>> @@ -55,9 +55,9 @@ static void putchar_vga(int ch) >>>>> */ >>>>> >>>>> /* Base Address */ >>>>> -uint8_t console_serial = 0; >>>>> -uint16_t serial_base = 0x3f8; /* TTYS0 */ >>>>> -uint32_t serial_baud = 0; >>>>> +uint8_t console_serial __data = 0; >>>>> +uint16_t serial_base __data = 0x3f8; /* TTYS0 */ >>>>> +uint32_t serial_baud __data = 0; >>>> >>>> Hmmm... I do not know why we need this patch. I can build kexec-tools >>>> in my env without it. I suppose that most of people can too. >>>> Could you check what is wrong with your build system? >>> >>> Regardless of whether it works with some tools, it doesn''t make a whole >>> lot of sense to try and set the value of symbols in the .bss section. >>> .bss is only for symbols with a value of zero. >> >> To be precise .bss is only for uninitialized symbols. Anyway, probably >> your compiler is screwed. In my case it sees that a given symbol is >> initialized and places it in .data section itself. > > David, are you using a compiler that doesn''t support > -fno-zero-initialized-in-bss? If that''s a supported optoin, then the > __data markers are indeed necessary.I''m using 4.7.2 and it does support the option and it is correctly being used when building purgatory. Not sure how I ended up with something that wasn''t working before. I''ll drop this patch. David