]> sourceware.org Git - libabigail.git/commitdiff
ctf-reader: looks for debug information in out-of-tree modules
authorGuillermo E. Martinez via Libabigail <libabigail@sourceware.org>
Mon, 15 Aug 2022 19:32:09 +0000 (14:32 -0500)
committerDodji Seketeli <dodji@redhat.com>
Mon, 29 Aug 2022 10:53:55 +0000 (12:53 +0200)
The archive `vmlinux.ctfa' contain CTF debug information for
all the types used by more than one module, CTF for the core
kernel and CTF for each module compiled in Linux tree directory.
CTF information for out-of-tree module is not present in
`vmlinux.ctfa' file, even so, the compiler can emit the `.ctf'
section into the out-of-tree modules and it can be extracted
by the libabigail tools.

* src/abg-ctf-reader.cc (process_ctf_archive, read_corpus
slurp_elf_info): Avoid looking for `vmlinux.ctfa' when we aren't
processing a `cur_corpus_group_'. So CTF info is embedded in the
`.ko' file.
* tests/data/Makefile.am: Add test inputs and expected files.
* tests/data/test-read-ctf/test-linux-module.{ko,c,abi}: Add new
test input and reference kABI.
* tests/test-read-ctf.cc: Add new testcase.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-ctf-reader.cc
tests/data/Makefile.am
tests/data/test-read-ctf/test-linux-module.abi [new file with mode: 0644]
tests/data/test-read-ctf/test-linux-module.c [new file with mode: 0644]
tests/data/test-read-ctf/test-linux-module.ko [new file with mode: 0644]
tests/test-read-ctf.cc

index c1ea15aac63105a6f56da292e17fdf574d030cc9..71808f9ad292b8bd3b5a79cb402681385cf3ef90 100644 (file)
@@ -1228,7 +1228,8 @@ process_ctf_archive(read_context *ctxt, corpus_sptr corp)
   filter.set_public_symbols();
   std::string dict_name;
 
-  if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
+  if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
+      && ctxt->cur_corpus_group_)
     {
       tools_utils::base_name(ctxt->filename, dict_name);
 
@@ -1472,7 +1473,8 @@ slurp_elf_info(read_context *ctxt,
   ABG_ASSERT(ctxt->symtab);
   corp->set_symtab(ctxt->symtab);
 
-  if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
+  if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
+      && ctxt->cur_corpus_group_)
     {
       status |= elf_reader::STATUS_OK;
       return;
@@ -1613,7 +1615,8 @@ read_corpus(read_context *ctxt, elf_reader::status &status)
    (ctxt->cur_corpus_->get_exported_decls_builder().get());
 
   int errp;
-  if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
+  if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
+      && ctxt->cur_corpus_group_)
     {
       if (ctxt->ctfa == NULL)
         {
index c7875b016d1c5ee9d23088861bcbd6962ea0af95..ebfce623683bb309811e66826396184372dadc54 100644 (file)
@@ -683,6 +683,9 @@ test-read-ctf/test-callback2.abi    \
 test-read-ctf/test-anonymous-fields.c  \
 test-read-ctf/test-anonymous-fields.o  \
 test-read-ctf/test-anonymous-fields.o.abi      \
+test-read-ctf/test-linux-module.abi            \
+test-read-ctf/test-linux-module.c              \
+test-read-ctf/test-linux-module.ko             \
 \
 test-annotate/test0.abi                        \
 test-annotate/test1.abi                        \
diff --git a/tests/data/test-read-ctf/test-linux-module.abi b/tests/data/test-read-ctf/test-linux-module.abi
new file mode 100644 (file)
index 0000000..d6bff4e
--- /dev/null
@@ -0,0 +1,65 @@
+<abi-corpus version='2.1' path='data/test-read-ctf/test-linux-module.ko'>
+  <elf-function-symbols>
+    <elf-symbol name='testexport' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes' crc='0x533ba8e8'/>
+    <elf-symbol name='testexport2' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes' crc='0x65900b2f'/>
+  </elf-function-symbols>
+  <elf-variable-symbols>
+    <elf-symbol name='global_sym' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes' crc='0x44a6713b'/>
+  </elf-variable-symbols>
+  <abi-instr address-size='64' language='LANG_C'>
+    <type-decl name='int' size-in-bits='32' alignment-in-bits='32' id='type-id-1'/>
+    <class-decl name='__raw_tickets' size-in-bits='32' alignment-in-bits='16' is-struct='yes' visibility='default' id='type-id-2'>
+      <data-member access='public' layout-offset-in-bits='0'>
+        <var-decl name='owner' type-id='type-id-3' visibility='default'/>
+      </data-member>
+      <data-member access='public' layout-offset-in-bits='16'>
+        <var-decl name='next' type-id='type-id-3' visibility='default'/>
+      </data-member>
+    </class-decl>
+    <class-decl name='arch_spinlock_t' size-in-bits='32' alignment-in-bits='32' is-struct='yes' naming-typedef-id='type-id-4' visibility='default' id='type-id-5'>
+      <data-member access='public' layout-offset-in-bits='0'>
+        <var-decl name='' type-id='type-id-6' visibility='default'/>
+      </data-member>
+    </class-decl>
+    <class-decl name='raw_spinlock' size-in-bits='32' alignment-in-bits='32' is-struct='yes' visibility='default' id='type-id-7'>
+      <data-member access='public' layout-offset-in-bits='0'>
+        <var-decl name='raw_lock' type-id='type-id-4' visibility='default'/>
+      </data-member>
+    </class-decl>
+    <class-decl name='spinlock' size-in-bits='32' alignment-in-bits='32' is-struct='yes' visibility='default' id='type-id-8'>
+      <data-member access='public' layout-offset-in-bits='0'>
+        <var-decl name='' type-id='type-id-9' visibility='default'/>
+      </data-member>
+    </class-decl>
+    <union-decl name='' size-in-bits='32' is-anonymous='yes' visibility='default' id='type-id-9'>
+      <data-member access='public'>
+        <var-decl name='rlock' type-id='type-id-7' visibility='default'/>
+      </data-member>
+    </union-decl>
+    <union-decl name='' size-in-bits='32' is-anonymous='yes' visibility='default' id='type-id-6'>
+      <data-member access='public'>
+        <var-decl name='slock' type-id='type-id-10' visibility='default'/>
+      </data-member>
+      <data-member access='public'>
+        <var-decl name='tickets' type-id='type-id-2' visibility='default'/>
+      </data-member>
+    </union-decl>
+    <type-decl name='unsigned int' size-in-bits='32' alignment-in-bits='32' id='type-id-11'/>
+    <type-decl name='unsigned short int' size-in-bits='16' alignment-in-bits='16' id='type-id-12'/>
+    <pointer-type-def type-id='type-id-13' size-in-bits='64' alignment-in-bits='64' id='type-id-14'/>
+    <function-decl name='testexport' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='8' elf-symbol-id='testexport'>
+      <return type-id='type-id-1'/>
+    </function-decl>
+    <function-decl name='testexport2' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='8' elf-symbol-id='testexport2'>
+      <parameter type-id='type-id-14'/>
+      <return type-id='type-id-1'/>
+    </function-decl>
+    <var-decl name='global_sym' type-id='type-id-1' mangled-name='global_sym' visibility='default' elf-symbol-id='global_sym'/>
+    <typedef-decl name='__u16' type-id='type-id-12' id='type-id-15'/>
+    <typedef-decl name='__u32' type-id='type-id-11' id='type-id-16'/>
+    <typedef-decl name='arch_spinlock_t' type-id='type-id-5' id='type-id-4'/>
+    <typedef-decl name='spinlock_t' type-id='type-id-8' id='type-id-13'/>
+    <typedef-decl name='u16' type-id='type-id-15' id='type-id-3'/>
+    <typedef-decl name='u32' type-id='type-id-16' id='type-id-10'/>
+  </abi-instr>
+</abi-corpus>
diff --git a/tests/data/test-read-ctf/test-linux-module.c b/tests/data/test-read-ctf/test-linux-module.c
new file mode 100644 (file)
index 0000000..4a647aa
--- /dev/null
@@ -0,0 +1,37 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+int global_sym = 0;
+EXPORT_SYMBOL(global_sym);
+static spinlock_t my_lock;
+
+int testexport(void)
+{
+  printk("in testexport\n");
+  return 0;
+}
+
+EXPORT_SYMBOL(testexport);
+
+int testexport2(spinlock_t *t)
+{
+  printk("in testexport\n");
+  return 0;
+}
+EXPORT_SYMBOL(testexport2);
+
+int hello_init(void)
+{
+  printk(KERN_INFO "Hello World!\n");
+  return 0;
+}
+
+void hello_exit(void)
+{
+  printk(KERN_INFO "Bye World!\n");
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+
+MODULE_LICENSE("GPL");
diff --git a/tests/data/test-read-ctf/test-linux-module.ko b/tests/data/test-read-ctf/test-linux-module.ko
new file mode 100644 (file)
index 0000000..c37d6e9
Binary files /dev/null and b/tests/data/test-read-ctf/test-linux-module.ko differ
index 994610b8ae00081a41a9b056518586d8a4e9bb83..b0ef7de655a2195f324b6ed940fcb126f7ca22cc 100644 (file)
@@ -293,6 +293,15 @@ static InOutSpec in_out_specs[] =
     "data/test-read-ctf/test-callback2.abi",
     "output/test-read-ctf/test-callback2.abi",
   },
+  // out-of-tree kernel module.
+  {
+    "data/test-read-ctf/test-linux-module.ko",
+    "",
+    "",
+    SEQUENCE_TYPE_ID_STYLE,
+    "data/test-read-ctf/test-linux-module.abi",
+    "output/test-read-ctf/test-linux-module.abi",
+  },
   // This should be the last entry.
   {NULL, NULL, NULL, SEQUENCE_TYPE_ID_STYLE, NULL, NULL}
 };
This page took 0.414107 seconds and 5 git commands to generate.