Skip to contentSkip to conversation

coverage: fix on ARM

PATCH In review Ian Campbell 4 participants 9 messages Feb 22, 2013 – Feb 28, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coverage: fix on ARM

Use a list of pointers to simplify the handling of 32- vs 64-bit.

Also on ARM the section name is ".init_array" and not ".ctors".

---
This applies independently of my 64-bit ARM series.

---
 xen/arch/arm/xen.lds.S |   10 ++++------
 xen/arch/x86/xen.lds.S |    6 ++----
 xen/common/lib.c       |   13 +++++--------
 3 files changed, 11 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +4 -6
index 9043994..fd755d7 100644
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)
 
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/arch/x86/xen.lds.S +2 -4
index 5570389..d959941 100644
@@ -110,11 +110,9 @@ SECTIONS
        __trampoline_seg_stop = .;
 
        . = ALIGN(8);
-       __CTOR_LIST__ = .;
-       QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
+       __ctors_start = .;
        *(.ctors)
-       QUAD(0)
-       __CTOR_END__ = .;
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/common/lib.c +5 -8
index e0c65cf..6b80601 100644
@@ -479,17 +479,14 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
     return ret;
 }
 
-extern const struct
-{
-    unsigned long count;
-    void (*funcs[1])(void);
-} __CTOR_LIST__;
+typedef void (*ctor_func_t)(void);
+extern const ctor_func_t __ctors_start[], __ctors_end[];
 
 void __init init_constructors(void)
 {
-    unsigned long n;
-    for ( n = 0; n < __CTOR_LIST__.count; ++n )
-        __CTOR_LIST__.funcs[n]();
+    const ctor_func_t *f;
+    for (f = __ctors_start; f < __ctors_end; ++f )
+        (*f)();
 }
 
 /*
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/arch/arm/xen.lds.S +0 -0
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)

xen/arch/arm/xen.lds.S SECTIONS · line 96

Quoted 10 lines
xen/arch/arm/xen.lds.S +3 -6
 
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)

Is this renaming from .ctors to .init_array really intended (i.e. was using .ctors here wrong)?

Jan

#2 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/arch/arm/xen.lds.S +0 -0
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)
 
Quoted 12 lines

xen/arch/arm/xen.lds.S SECTIONS · line 96

Quoted 9 lines
xen/arch/arm/xen.lds.S +3 -6
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)

Is this renaming from .ctors to .init_array really intended (i.e. was using .ctors here wrong)?

Yes, I mentioned it in the commit message, it is called .init_array on ARM for whatever reason. Probably either historical accident or compatibility eg. with ARM's compilers.

Ian.

#3 lore raw
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/arch/arm/xen.lds.S +0 -0
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)
 
Quoted 12 lines

xen/arch/arm/xen.lds.S SECTIONS · line 96

Quoted 9 lines
xen/arch/arm/xen.lds.S +3 -6
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)

Is this renaming from .ctors to .init_array really intended (i.e. was using .ctors here wrong)?

Quoted 1 line

Yes, I mentioned it in the commit message,

Oops, sorry, managed to skip that line somehow.

Quoted 3 lines

it is called .init_array on
ARM for whatever reason. Probably either historical accident or compatibility eg. with ARM's compilers.

Or rather the other way around, because .init_array is a (newer) ELF concept, whereas .ctors isn't.

Jan

#4 lore raw
Quoted 24 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/arch/arm/xen.lds.S +0 -0
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)
 
Quoted 12 lines

xen/arch/arm/xen.lds.S SECTIONS · line 96

Quoted 9 lines
xen/arch/arm/xen.lds.S +3 -6
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)

Is this renaming from .ctors to .init_array really intended (i.e. was using .ctors here wrong)?

Quoted 1 line

Yes, I mentioned it in the commit message,

Quoted 8 lines

Oops, sorry, managed to skip that line somehow.

Quoted 3 lines

it is called .init_array on
ARM for whatever reason. Probably either historical accident or compatibility eg. with ARM's compilers.

Or rather the other way around, because .init_array is a (newer) ELF concept, whereas .ctors isn't.

Ah, that explains it, thanks!

Ian.

#5 lore raw
In reply to Ian Campbell
Quoted 3 lines · Ian Campbell

Use a list of pointers to simplify the handling of 32- vs 64-bit.

Also on ARM the section name is ".init_array" and not ".ctors".

Any comments/ack/nacks?

Quoted 77 lines

---
This applies independently of my 64-bit ARM series.

---
 xen/arch/arm/xen.lds.S |   10 ++++------
 xen/arch/x86/xen.lds.S |    6 ++----
 xen/common/lib.c       |   13 +++++--------
 3 files changed, 11 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +4 -6
index 9043994..fd755d7 100644
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)
 
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/arch/x86/xen.lds.S +2 -4
index 5570389..d959941 100644
@@ -110,11 +110,9 @@ SECTIONS
        __trampoline_seg_stop = .;
 
        . = ALIGN(8);
-       __CTOR_LIST__ = .;
-       QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
+       __ctors_start = .;
        *(.ctors)
-       QUAD(0)
-       __CTOR_END__ = .;
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/common/lib.c +5 -8
index e0c65cf..6b80601 100644
@@ -479,17 +479,14 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
     return ret;
 }
 
-extern const struct
-{
-    unsigned long count;
-    void (*funcs[1])(void);
-} __CTOR_LIST__;
+typedef void (*ctor_func_t)(void);
+extern const ctor_func_t __ctors_start[], __ctors_end[];
 
 void __init init_constructors(void)
 {
-    unsigned long n;
-    for ( n = 0; n < __CTOR_LIST__.count; ++n )
-        __CTOR_LIST__.funcs[n]();
+    const ctor_func_t *f;
+    for (f = __ctors_start; f < __ctors_end; ++f )
+        (*f)();
 }
 
 /*
#6 lore raw
Quoted 6 lines · Ian Campbell
Quoted 3 lines · Ian Campbell

Use a list of pointers to simplify the handling of 32- vs 64-bit.

Also on ARM the section name is ".init_array" and not ".ctors".

Any comments/ack/nacks?

If it works, it's good by me ;)

-- Keir

Quoted 80 lines
Quoted 78 lines

---
This applies independently of my 64-bit ARM series.

---
 xen/arch/arm/xen.lds.S |   10 ++++------
 xen/arch/x86/xen.lds.S |    6 ++----
 xen/common/lib.c       |   13 +++++--------
 3 files changed, 11 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +4 -6
index 9043994..fd755d7 100644
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)
 
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/arch/x86/xen.lds.S +2 -4
index 5570389..d959941 100644
@@ -110,11 +110,9 @@ SECTIONS
        __trampoline_seg_stop = .;
 
        . = ALIGN(8);
-       __CTOR_LIST__ = .;
-       QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
+       __ctors_start = .;
        *(.ctors)
-       QUAD(0)
-       __CTOR_END__ = .;
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/common/lib.c +5 -8
index e0c65cf..6b80601 100644
@@ -479,17 +479,14 @@ unsigned long long parse_size_and_unit(const char *s,
 const char **ps)
     return ret;
 }
 
-extern const struct
-{
-    unsigned long count;
-    void (*funcs[1])(void);
-} __CTOR_LIST__;
+typedef void (*ctor_func_t)(void);
+extern const ctor_func_t __ctors_start[], __ctors_end[];
 
 void __init init_constructors(void)
 {
-    unsigned long n;
-    for ( n = 0; n < __CTOR_LIST__.count; ++n )
-        __CTOR_LIST__.funcs[n]();
+    const ctor_func_t *f;
+    for (f = __ctors_start; f < __ctors_end; ++f )
+        (*f)();
 }
 

/*

#7 lore raw
In reply to Ian Campbell
Quoted 7 lines · Ian Campbell
Quoted 3 lines · Ian Campbell

Use a list of pointers to simplify the handling of 32- vs 64-bit.

Also on ARM the section name is ".init_array" and not ".ctors".

Any comments/ack/nacks?

Looks fine to me. Did you test it? Actually the way I test is:
- compile with coverage
- run xencov to extract information (more or less for x64 is 500k)
- check file content to see if counters increase while taking multiple snapshot (xencov read - | hexdump -C | tail -100, counters are after 0CTX string which means "Xen Test Coverage count 0")
- reset counters (but this has nothing to do with constructors)

I actually cannot test for Arm.

Oh.. there is a missing space after a "for("

Frediano

Quoted 79 lines
Quoted 77 lines

---
This applies independently of my 64-bit ARM series.

---
 xen/arch/arm/xen.lds.S |   10 ++++------
 xen/arch/x86/xen.lds.S |    6 ++----
 xen/common/lib.c       |   13 +++++--------
 3 files changed, 11 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +4 -6
index 9043994..fd755d7 100644
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)
 
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/arch/x86/xen.lds.S +2 -4
index 5570389..d959941 100644
@@ -110,11 +110,9 @@ SECTIONS
        __trampoline_seg_stop = .;
 
        . = ALIGN(8);
-       __CTOR_LIST__ = .;
-       QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
+       __ctors_start = .;
        *(.ctors)
-       QUAD(0)
-       __CTOR_END__ = .;
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/common/lib.c +5 -8
index e0c65cf..6b80601 100644
@@ -479,17 +479,14 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
     return ret;
 }
 
-extern const struct
-{
-    unsigned long count;
-    void (*funcs[1])(void);
-} __CTOR_LIST__;
+typedef void (*ctor_func_t)(void);
+extern const ctor_func_t __ctors_start[], __ctors_end[];
 
 void __init init_constructors(void)
 {
-    unsigned long n;
-    for ( n = 0; n < __CTOR_LIST__.count; ++n )
-        __CTOR_LIST__.funcs[n]();
+    const ctor_func_t *f;
+    for (f = __ctors_start; f < __ctors_end; ++f )
+        (*f)();
 }
 
 /*
#8 lore raw
Quoted 10 lines · Frediano Ziglio
Quoted 7 lines · Ian Campbell
Quoted 3 lines · Ian Campbell

Use a list of pointers to simplify the handling of 32- vs 64-bit.

Also on ARM the section name is ".init_array" and not ".ctors".

Any comments/ack/nacks?

Looks fine to me. Did you test it?

I tested on x86_64 and arm32/64 by annotating the init function to print the function names as it called them and observing that a) a bunch of functions were called (on x86 it looked similar before and after this change) and b) it didn't crash.

Quoted 11 lines

Actually the way I test is:
- compile with coverage
- run xencov to extract information (more or less for x64 is 500k)
- check file content to see if counters increase while taking multiple snapshot (xencov read - | hexdump -C | tail -100, counters are after 0CTX string which means "Xen Test Coverage count 0")
- reset counters (but this has nothing to do with constructors)

I actually cannot test for Arm.

Oh.. there is a missing space after a "for("

So there is, thanks for spotting. A resend will have to wait until after my flight to Hong Kong or else whoever applies, which may end up being me, can fix it as they go.

Cheers,
Ian.

Quoted 83 lines

Frediano

Quoted 79 lines
Quoted 77 lines

---
This applies independently of my 64-bit ARM series.

---
 xen/arch/arm/xen.lds.S |   10 ++++------
 xen/arch/x86/xen.lds.S |    6 ++----
 xen/common/lib.c       |   13 +++++--------
 3 files changed, 11 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +4 -6
index 9043994..fd755d7 100644
@@ -91,12 +91,10 @@ SECTIONS
        *(.init.data.rel)
        *(.init.data.rel.*)
 
-       . = ALIGN(4);
-       __CTOR_LIST__ = .;
-       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
-       *(.ctors)
-       LONG(0)
-       __CTOR_END__ = .;
+       . = ALIGN(8);
+       __ctors_start = .;
+       *(.init_array)
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/arch/x86/xen.lds.S +2 -4
index 5570389..d959941 100644
@@ -110,11 +110,9 @@ SECTIONS
        __trampoline_seg_stop = .;
 
        . = ALIGN(8);
-       __CTOR_LIST__ = .;
-       QUAD((__CTOR_END__ - __CTOR_LIST__) / 8 - 2)
+       __ctors_start = .;
        *(.ctors)
-       QUAD(0)
-       __CTOR_END__ = .;
+       __ctors_end = .;
   } :text
   . = ALIGN(32);
   .init.setup : {
xen/common/lib.c +5 -8
index e0c65cf..6b80601 100644
@@ -479,17 +479,14 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
     return ret;
 }
 
-extern const struct
-{
-    unsigned long count;
-    void (*funcs[1])(void);
-} __CTOR_LIST__;
+typedef void (*ctor_func_t)(void);
+extern const ctor_func_t __ctors_start[], __ctors_end[];
 
 void __init init_constructors(void)
 {
-    unsigned long n;
-    for ( n = 0; n < __CTOR_LIST__.count; ++n )
-        __CTOR_LIST__.funcs[n]();
+    const ctor_func_t *f;
+    for (f = __ctors_start; f < __ctors_end; ++f )
+        (*f)();
 }
 
 /*