summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/classes/package.bbclass202
1 files changed, 97 insertions, 105 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index 679055ff1b..164e38c505 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -722,8 +722,9 @@ python split_and_strip_files () {
722 # 722 #
723 # First lets figure out all of the files we may have to process ... do this only once! 723 # First lets figure out all of the files we may have to process ... do this only once!
724 # 724 #
725 file_list = {} 725 elffiles = {}
726 file_links = {} 726 symlinks = {}
727 hardlinks = {}
727 kernmods = [] 728 kernmods = []
728 if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT', True) != '1') and \ 729 if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT', True) != '1') and \
729 (d.getVar('INHIBIT_PACKAGE_STRIP', True) != '1'): 730 (d.getVar('INHIBIT_PACKAGE_STRIP', True) != '1'):
@@ -734,119 +735,111 @@ python split_and_strip_files () {
734 kernmods.append(file) 735 kernmods.append(file)
735 continue 736 continue
736 737
737 # Only process files (and symlinks)... Skip files that are obviously debug files 738 # Skip debug files
738 if not (debugappend != "" and file.endswith(debugappend)) and \ 739 if debugappend and file.endswith(debugappend):
739 not (debugdir != "" and debugdir in os.path.dirname(file[len(dvar):])) and \ 740 continue
740 os.path.isfile(file): 741 if debugdir and debugdir in os.path.dirname(file[len(dvar):]):
741 try: 742 continue
742 s = os.stat(file) 743
743 except OSError, (err, strerror): 744 try:
744 if err != errno.ENOENT: 745 s = os.stat(file)
745 raise 746 except OSError, (err, strerror):
746 # Skip broken symlinks 747 if err != errno.ENOENT:
748 raise
749 # Skip broken symlinks
750 continue
751 # Check its an excutable
752 if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH):
753 # If it's a symlink, and points to an ELF file, we capture the readlink target
754 if os.path.islink(file):
755 target = os.readlink(file)
756 if not os.path.isabs(target):
757 ltarget = os.path.join(os.path.dirname(file), target)
758 else:
759 ltarget = target
760
761 if isELF(ltarget):
762 #bb.note("Sym: %s (%d)" % (ltarget, isELF(ltarget)))
763 symlinks[file] = target
747 continue 764 continue
748 # Is the item excutable? Then we need to process it. 765 # It's a file (or hardlink), not a link
749 if (s[stat.ST_MODE] & stat.S_IXUSR) or \ 766 # ...but is it ELF, and is it already stripped?
750 (s[stat.ST_MODE] & stat.S_IXGRP) or \ 767 elf_file = isELF(file)
751 (s[stat.ST_MODE] & stat.S_IXOTH): 768 if elf_file & 1:
752 # If it's a symlink, and points to an ELF file, we capture the readlink target 769 if elf_file & 2:
753 if os.path.islink(file): 770 bb.warn("File '%s' from %s was already stripped, this will prevent future debugging!" % (src, pn))
754 target = os.readlink(file)
755 if not os.path.isabs(target):
756 ltarget = os.path.join(os.path.dirname(file), target)
757 else:
758 ltarget = target
759
760 if isELF(ltarget):
761 #bb.note("Sym: %s (%d)" % (ltarget, isELF(ltarget)))
762 file_list[file] = "sym: " + target
763 continue 771 continue
764 # It's a file (or hardlink), not a link 772 # Check if it's a hard link to something else
765 # ...but is it ELF, and is it already stripped? 773 if s.st_nlink > 1:
766 elf_file = isELF(file) 774 file_reference = "%d_%d" % (s.st_dev, s.st_ino)
767 if elf_file & 1: 775 # Hard link to something else
768 # Check if it's a hard link to something else 776 hardlinks[file] = file_reference
769 if s.st_nlink > 1: 777 continue
770 file_reference = "%d_%d" % (s.st_dev, s.st_ino) 778 elffiles[file] = elf_file
771 # Hard link to something else
772 file_list[file] = "hard: " + file_reference
773 continue
774
775 file_list[file] = "ELF: %d" % elf_file
776
777 779
778 # 780 #
779 # First lets process debug splitting 781 # First lets process debug splitting
780 # 782 #
781 if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT', True) != '1'): 783 if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT', True) != '1'):
782 for file in file_list: 784 hardlinkmap = {}
785 # For hardlinks, process only one of the files
786 for file in hardlinks:
787 file_reference = hardlinks[file]
788 if file_reference not in hardlinkmap:
789 # If this is a new file, add it as a reference, and
790 # update it's type, so we can fall through and split
791 elffiles[file] = isELF(file)
792 hardlinkmap[file_reference] = file
793
794 for file in elffiles:
783 src = file[len(dvar):] 795 src = file[len(dvar):]
784 dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend 796 dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend
785 fpath = dvar + dest 797 fpath = dvar + dest
786 # Preserve symlinks in debug area...
787 if file_list[file].startswith("sym: "):
788 ltarget = file_list[file][5:]
789 lpath = os.path.dirname(ltarget)
790 lbase = os.path.basename(ltarget)
791 ftarget = ""
792 if lpath and lpath != ".":
793 ftarget += lpath + debugdir + "/"
794 ftarget += lbase + debugappend
795 if lpath.startswith(".."):
796 ftarget = os.path.join("..", ftarget)
797 bb.mkdirhier(os.path.dirname(fpath))
798 #bb.note("Symlink %s -> %s" % (fpath, ftarget))
799 os.symlink(ftarget, fpath)
800 continue
801 798
802 # Preserve hard links in debug area... 799 # Split the file...
803 file_reference = "" 800 bb.utils.mkdirhier(os.path.dirname(fpath))
804 if file_list[file].startswith("hard: "): 801 #bb.note("Split %s -> %s" % (file, fpath))
805 file_reference = file_list[file][6:] 802 # Only store off the hard link reference if we successfully split!
806 if file_reference not in file_links: 803 splitdebuginfo(file, fpath, debugsrcdir, d)
807 # If this is a new file, add it as a reference, and
808 # update it's type, so we can fall through and split
809 file_list[file] = "ELF: %d" % (isELF(file))
810 else:
811 target = file_links[file_reference][len(dvar):]
812 ftarget = dvar + debuglibdir + os.path.dirname(target) + debugdir + "/" + os.path.basename(target) + debugappend
813 bb.mkdirhier(os.path.dirname(fpath))
814 #bb.note("Link %s -> %s" % (fpath, ftarget))
815 os.link(ftarget, fpath)
816 continue
817
818 # It's ELF...
819 if file_list[file].startswith("ELF: "):
820 elf_file = int(file_list[file][5:])
821 if elf_file & 2:
822 bb.warn("File '%s' from %s was already stripped, this will prevent future debugging!" % (src, pn))
823 continue
824 804
825 # Split the file... 805 # Hardlink our debug symbols to the other hardlink copies
826 bb.mkdirhier(os.path.dirname(fpath)) 806 for file in hardlinks:
827 #bb.note("Split %s -> %s" % (file, fpath)) 807 if file not in elffiles:
828 # Only store off the hard link reference if we successfully split!
829 if splitdebuginfo(file, fpath, debugsrcdir, d) == 0 and file_reference != "":
830 file_links[file_reference] = file
831
832 # The above may have generated dangling symlinks, remove them!
833 # Dangling symlinks are a result of something NOT being split, such as a stripped binary.
834 # This should be a rare occurance, but we want to clean up anyway.
835 for file in file_list:
836 if file_list[file].startswith("sym: "):
837 src = file[len(dvar):] 808 src = file[len(dvar):]
838 dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend 809 dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend
839 fpath = dvar + dest 810 fpath = dvar + dest
840 try: 811 file_reference = hardlinks[file]
841 s = os.stat(fpath) 812 target = hardlinkmap[file_reference][len(dvar):]
842 except OSError, (err, strerror): 813 ftarget = dvar + debuglibdir + os.path.dirname(target) + debugdir + "/" + os.path.basename(target) + debugappend
843 if err != errno.ENOENT: 814 bb.utils.mkdirhier(os.path.dirname(fpath))
844 raise 815 #bb.note("Link %s -> %s" % (fpath, ftarget))
845 #bb.note("Remove dangling link %s -> %s" % (fpath, os.readlink(fpath))) 816 os.link(ftarget, fpath)
846 os.unlink(fpath) 817
847 # This could leave an empty debug directory laying around 818 # Create symlinks for all cases we were able to split symbols
848 # take care of the obvious case... 819 for file in symlinks:
849 subprocess.call("rmdir %s 2>/dev/null" % os.path.dirname(fpath), shell=True) 820 src = file[len(dvar):]
821 dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend
822 fpath = dvar + dest
823 # Skip it if the target doesn't exist
824 try:
825 s = os.stat(fpath)
826 except OSError, (err, strerror):
827 if err != errno.ENOENT:
828 raise
829 continue
830
831 ltarget = symlinks[file]
832 lpath = os.path.dirname(ltarget)
833 lbase = os.path.basename(ltarget)
834 ftarget = ""
835 if lpath and lpath != ".":
836 ftarget += lpath + debugdir + "/"
837 ftarget += lbase + debugappend
838 if lpath.startswith(".."):
839 ftarget = os.path.join("..", ftarget)
840 bb.utils.mkdirhier(os.path.dirname(fpath))
841 #bb.note("Symlink %s -> %s" % (fpath, ftarget))
842 os.symlink(ftarget, fpath)
850 843
851 # Process the debugsrcdir if requested... 844 # Process the debugsrcdir if requested...
852 # This copies and places the referenced sources for later debugging... 845 # This copies and places the referenced sources for later debugging...
@@ -861,11 +854,10 @@ python split_and_strip_files () {
861 if (d.getVar('INHIBIT_PACKAGE_STRIP', True) != '1'): 854 if (d.getVar('INHIBIT_PACKAGE_STRIP', True) != '1'):
862 strip = d.getVar("STRIP", True) 855 strip = d.getVar("STRIP", True)
863 sfiles = [] 856 sfiles = []
864 for file in file_list: 857 for file in elffiles:
865 if file_list[file].startswith("ELF: "): 858 elf_file = int(elffiles[file])
866 elf_file = int(file_list[file][5:]) 859 #bb.note("Strip %s" % file)
867 #bb.note("Strip %s" % file) 860 sfiles.append((file, elf_file, strip))
868 sfiles.append((file, elf_file, strip))
869 for f in kernmods: 861 for f in kernmods:
870 sfiles.append((f, 16, strip)) 862 sfiles.append((f, 16, strip))
871 863