[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: libc dlopening libgcc on arm



On Wed, May 30, 2007 at 10:30:05AM +0200, Bastian Blank wrote:
> D-I may be also affected and mklibs needs to pull in libgcc_s.so.1
> always if it catches a glibc.

The attached mklibs patch always adds libgcc for old-abi arm.

Bastian

-- 
Well, Jim, I'm not much of an actor either.
Index: debian/control
===================================================================
--- debian/control	(revision 108)
+++ debian/control	(working copy)
@@ -8,7 +8,7 @@
 
 Package: mklibs
 Architecture: all
-Depends: python, binutils, gcc, mklibs-copy (>= 0.1.21)
+Depends: python, binutils, gcc, mklibs-copy (>= ${source:Version})
 Recommends: libc6-pic | libc6.1-pic
 Description: Shared library reduction script
  mklibs produces cut-down shared libraries that contain only the
Index: src/mklibs-copy.py
===================================================================
--- src/mklibs-copy.py	(revision 108)
+++ src/mklibs-copy.py	(working copy)
@@ -65,6 +65,13 @@
 
     return result
 
+def elf_header(obj):
+    if not os.access(obj, os.F_OK):
+        raise "Cannot find lib: " + obj
+    output = command("mklibs-readelf", "--print-elf-header", obj)
+    s = [int(i) for i in output[0].split()]
+    return {'class': s[0], 'data': s[1], 'machine': s[2], 'flags': s[3]}
+
 # Return a set of rpath strings for the passed object
 def rpath(obj):
     if not os.access(obj, os.F_OK):
@@ -278,6 +285,11 @@
 
     previous_pass_libraries = libraries
 
+    # WORKAROUND: Always add libgcc on old-abi arm
+    header = elf_header(find_lib(libraries.copy().pop()))
+    if header['machine'] == 40 and header['flags'] & 0xff000000 == 0:
+        libraries.add('libgcc_s.so.1')  
+
     # reduce libraries
     for library in libraries:
         so_file = find_lib(library)
Index: src/mklibs-readelf/main.cpp
===================================================================
--- src/mklibs-readelf/main.cpp	(revision 112)
+++ src/mklibs-readelf/main.cpp	(working copy)
@@ -18,6 +18,7 @@
 
 static struct option const long_opts[] =
 { 
+  {"print-elf-header", no_argument, 0, 'e'},
   {"print-interp", no_argument, 0, 'i'},
   {"print-needed", no_argument, 0, 'n'},
   {"print-rpath", no_argument, 0, 'R'},
@@ -33,6 +34,7 @@
 
 enum command
 {
+  COMMAND_PRINT_ELF_HEADER,
   COMMAND_PRINT_INTERP,
   COMMAND_PRINT_NEEDED,
   COMMAND_PRINT_RPATH,
@@ -41,6 +43,15 @@
   COMMAND_PRINT_SYMBOLS_UNDEFINED,
 };
 
+static void process_elf_header (Elf::file *file)
+{
+  std::cout
+    << (unsigned int) file->get_class () << ' '
+    << (unsigned int) file->get_data () << ' '
+    << file->get_machine () << ' '
+    << file->get_flags () << '\n';
+}
+
 static void process_dynamics (Elf::section_type<Elf::section_type_DYNAMIC> *section, int64_t tag)
 {
   for (std::vector<Elf::dynamic *>::const_iterator it = section->get_dynamics ().begin (); it != section->get_dynamics ().end (); ++it)
@@ -108,6 +119,9 @@
 
   switch (cmd)
   {
+    case COMMAND_PRINT_ELF_HEADER:
+      process_elf_header (file);
+      break;
     case COMMAND_PRINT_INTERP:
       if (segment_interp)
         std::cout << segment_interp->get_interp () << '\n';
@@ -166,12 +180,15 @@
 
   program_name = argv[0];
 
-  while ((c = getopt_long (argc, argv, "inpRsu", long_opts, NULL)) != -1)
+  while ((c = getopt_long (argc, argv, "einpRsu", long_opts, NULL)) != -1)
   {
     switch (c)
     { 
       case 0:
         break;
+      case 'e':
+        cmd = COMMAND_PRINT_ELF_HEADER;
+        break;
       case 'i':
         cmd = COMMAND_PRINT_INTERP;
         break;
Index: src/mklibs-readelf/elf.cpp
===================================================================
--- src/mklibs-readelf/elf.cpp	(revision 105)
+++ src/mklibs-readelf/elf.cpp	(working copy)
@@ -150,6 +150,7 @@
   this->machine   = convert<_data, typeof (ehdr->e_machine  )> () (ehdr->e_machine);
   this->phoff     = convert<_data, typeof (ehdr->e_phoff    )> () (ehdr->e_phoff);
   this->shoff     = convert<_data, typeof (ehdr->e_shoff    )> () (ehdr->e_shoff);
+  this->flags     = convert<_data, typeof (ehdr->e_flags    )> () (ehdr->e_flags);
   this->phentsize = convert<_data, typeof (ehdr->e_phentsize)> () (ehdr->e_phentsize);
   this->phnum     = convert<_data, typeof (ehdr->e_phnum    )> () (ehdr->e_phnum);
   this->shentsize = convert<_data, typeof (ehdr->e_shentsize)> () (ehdr->e_shentsize);
Index: src/mklibs-readelf/elf.hpp
===================================================================
--- src/mklibs-readelf/elf.hpp	(revision 105)
+++ src/mklibs-readelf/elf.hpp	(working copy)
@@ -31,15 +31,15 @@
 
 namespace Elf
 {
-  class file_class_32 { public: static const unsigned int id = 1; };
-  class file_class_64 { public: static const unsigned int id = 2; };
-  class file_data_2LSB { public: static const unsigned int id = 1; };
-  class file_data_2MSB { public: static const unsigned int id = 2; };
+  class file_class_32 { public: static const uint8_t id = 1; };
+  class file_class_64 { public: static const uint8_t id = 2; };
+  class file_data_2LSB { public: static const uint8_t id = 1; };
+  class file_data_2MSB { public: static const uint8_t id = 2; };
   class section_type_UNDEFINED { };
-  class section_type_DYNAMIC { public: static const unsigned int id = 6; };
-  class section_type_DYNSYM { public: static const unsigned int id = 11; };
+  class section_type_DYNAMIC { public: static const uint8_t id = 6; };
+  class section_type_DYNSYM { public: static const uint8_t id = 11; };
   class segment_type_UNDEFINED { };
-  class segment_type_INTERP { public: static const unsigned int id = 3; };
+  class segment_type_INTERP { public: static const uint8_t id = 3; };
 
   class section;
   class segment;
@@ -53,6 +53,7 @@
       virtual const uint8_t get_data () const throw () = 0;
       const uint16_t get_type () const throw () { return type; }
       const uint16_t get_machine () const throw () { return machine; }
+      const uint32_t get_flags () const throw () { return flags; }
       const uint16_t get_shstrndx () const throw () { return shstrndx; }
 
       const std::vector <section *> get_sections () const throw () { return sections; };
@@ -73,6 +74,7 @@
       uint16_t machine;
       uint64_t phoff;
       uint64_t shoff;
+      uint32_t flags;
       uint16_t phentsize;
       uint16_t phnum;
       uint16_t shentsize;
Index: src/mklibs.py
===================================================================
--- src/mklibs.py	(revision 109)
+++ src/mklibs.py	(working copy)
@@ -83,6 +83,13 @@
 
     return result
 
+def elf_header(obj):
+    if not os.access(obj, os.F_OK):
+        raise "Cannot find lib: " + obj
+    output = command("mklibs-readelf", "--print-elf-header", obj)
+    s = [int(i) for i in output[0].split()]
+    return {'class': s[0], 'data': s[1], 'machine': s[2], 'flags': s[3]}
+
 # Return a set of rpath strings for the passed object
 def rpath(obj):
     if not os.access(obj, os.F_OK):
@@ -400,6 +407,11 @@
     library_symbols_used = {}
     symbol_provider = {}
 
+    # WORKAROUND: Always add libgcc on old-abi arm
+    header = elf_header(find_lib(libraries.copy().pop()))
+    if header['machine'] == 40 and header['flags'] & 0xff000000 == 0:
+        libraries.add('libgcc_s.so.1')
+
     # Calculate all symbols each library provides
     for library in libraries:
         path = find_lib(library)

Attachment: signature.asc
Description: Digital signature


Reply to: