Exemple #1
0
    def test_catch_all_placement(self):
        # Test default (catch-all) command
        expected = '*(.literal .literal.* .text .text.*)'

        desc = InputSectionDesc(Entity(), SECTIONS)
        self.assertEqual(expected, str(desc))

        desc = InputSectionDesc(Entity(Entity.ALL), SECTIONS)
        self.assertEqual(expected, str(desc))
Exemple #2
0
    def test_invalid_entity(self):
        # Invalid entity specification
        with self.assertRaises(AssertionError):
            InputSectionDesc(Entity('libfreertos.a', 'croutine', 'prvCheckPendingReadyList'), SECTIONS)

        with self.assertRaises(AssertionError):
            InputSectionDesc(Entity('libfreertos.a', 'croutine'), SECTIONS, [Entity()])

        with self.assertRaises(AssertionError):
            InputSectionDesc(Entity('libfreertos.a', 'croutine'), SECTIONS, [Entity('libfreertos.a', 'croutine', 'prvCheckPendingReadyList')])
Exemple #3
0
    def test_lib_placement(self):
        # Test library placement command
        expected = '*libfreertos.a:(.literal .literal.* .text .text.*)'

        desc = InputSectionDesc(Entity('libfreertos.a'), SECTIONS)
        self.assertEqual(expected, str(desc))

        desc = InputSectionDesc(Entity('libfreertos.a', Entity.ALL), SECTIONS)
        self.assertEqual(expected, str(desc))

        desc = InputSectionDesc(Entity('libfreertos.a', None, Entity.ALL), SECTIONS)
        self.assertEqual(expected, str(desc))

        desc = InputSectionDesc(Entity('libfreertos.a', Entity.ALL, Entity.ALL), SECTIONS)
        self.assertEqual(expected, str(desc))
Exemple #4
0
    def test_obj_placement(self):
        # Test object placement command
        expected = '*libfreertos.a:croutine.*(.literal .literal.* .text .text.*)'

        desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), SECTIONS)
        self.assertEqual(expected, str(desc))

        desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), SECTIONS)
        self.assertEqual(expected, str(desc))

        desc = InputSectionDesc(Entity('libfreertos.a', 'croutine', Entity.ALL), SECTIONS)
        self.assertEqual(expected, str(desc))

        # Disambugated placement
        expected = '*libfreertos.a:croutine.c.*(.literal .literal.* .text .text.*)'

        desc = InputSectionDesc(Entity('libfreertos.a', 'croutine.c'), SECTIONS)
        self.assertEqual(expected, str(desc))
Exemple #5
0
    def get_node_output_commands(self):
        commands = collections.defaultdict(list)

        for sections in self.get_section_keys():
            info = self.sections[sections]
            if info.explicit:
                command = InputSectionDesc(Entity(self.parent.parent.name, self.parent.name), sections, [])
                commands[info.target].append(command)

        return commands
Exemple #6
0
    def get_node_output_commands(self):
        commands = collections.defaultdict(list)

        for sections in self.get_section_keys():
            info = self.sections[sections]
            if info.exclusions or info.explicit:
                command = InputSectionDesc(self.entity, sections, info.exclusions)
                commands[info.target].append(command)

        return commands
    def test_output_04(self):
        # Test exclusions

        # Library
        expected = ('*libfreertos.a:croutine.*'
                    '(EXCLUDE_FILE(*libfreertos.a) '
                    '.literal EXCLUDE_FILE(*libfreertos.a) '
                    '.literal.* EXCLUDE_FILE(*libfreertos.a) '
                    '.text EXCLUDE_FILE(*libfreertos.a) .text.*)')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [FREERTOS])
        self.assertEqual(expected, str(desc))

        # Object
        expected = ('*libfreertos.a:croutine.*'
                    '(EXCLUDE_FILE(*libfreertos.a:croutine.*) '
                    '.literal EXCLUDE_FILE(*libfreertos.a:croutine.*) '
                    '.literal.* EXCLUDE_FILE(*libfreertos.a:croutine.*) '
                    '.text EXCLUDE_FILE(*libfreertos.a:croutine.*) .text.*)')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [CROUTINE])
        self.assertEqual(expected, str(desc))

        # Multiple exclusions
        expected = (
            '*libfreertos.a:croutine.*'
            '(EXCLUDE_FILE(*libfreertos.a *libfreertos.a:croutine.*) '
            '.literal EXCLUDE_FILE(*libfreertos.a *libfreertos.a:croutine.*) '
            '.literal.* EXCLUDE_FILE(*libfreertos.a *libfreertos.a:croutine.*) '
            '.text EXCLUDE_FILE(*libfreertos.a *libfreertos.a:croutine.*) .text.*)'
        )
        desc = InputSectionDesc(CROUTINE, SECTIONS, [FREERTOS, CROUTINE])
        self.assertEqual(expected, str(desc))

        # Disambugated exclusion
        expected = ('*libfreertos.a:croutine.*'
                    '(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) '
                    '.literal EXCLUDE_FILE(*libfreertos.a:croutine.c.*) '
                    '.literal.* EXCLUDE_FILE(*libfreertos.a:croutine.c.*) '
                    '.text EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*)')
        desc = InputSectionDesc(CROUTINE, SECTIONS,
                                [Entity('libfreertos.a', 'croutine.c')])
        self.assertEqual(expected, str(desc))
Exemple #8
0
    def get_node_output_commands(self):
        commands = collections.defaultdict(list)

        for sections in self.get_section_keys():
            info = self.sections[sections]

            try:
                match_sections = self.expanded_sections[sections]
            except KeyError:
                match_sections = []

            if match_sections or info.explicit:
                command_sections = match_sections if match_sections else sections
                command = InputSectionDesc(self.entity, command_sections, [])
                commands[info.target].append(command)

        return commands
Exemple #9
0
    def test_sort(self):
        # Test sort
        expected = ('*libfreertos.a:croutine.*('
                    'SORT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal) '
                    'SORT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal.*) '
                    'SORT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text) '
                    'SORT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*)'
                    ')')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')], keep=False, sort=(None, None))
        self.assertEqual(expected, str(desc))

        expected = ('*libfreertos.a:croutine.*('
                    'SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal) '
                    'SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal.*) '
                    'SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text) '
                    'SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*)'
                    ')')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')], keep=False, sort=('name', None))
        self.assertEqual(expected, str(desc))

        expected = ('*libfreertos.a:croutine.*('
                    'SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal) '
                    'SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal.*) '
                    'SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text) '
                    'SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*)'
                    ')')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')], keep=False, sort=('alignment', None))
        self.assertEqual(expected, str(desc))

        expected = ('*libfreertos.a:croutine.*('
                    'SORT_BY_INIT_PRIORITY(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal) '
                    'SORT_BY_INIT_PRIORITY(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal.*) '
                    'SORT_BY_INIT_PRIORITY(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text) '
                    'SORT_BY_INIT_PRIORITY(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*)'
                    ')')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')], keep=False, sort=('init_priority', None))
        self.assertEqual(expected, str(desc))

        expected = ('*libfreertos.a:croutine.*('
                    'SORT_BY_NAME(SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal)) '
                    'SORT_BY_NAME(SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal.*)) '
                    'SORT_BY_NAME(SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text)) '
                    'SORT_BY_NAME(SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*))'
                    ')')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')], keep=False, sort=('name', 'alignment'))
        self.assertEqual(expected, str(desc))

        expected = ('*libfreertos.a:croutine.*('
                    'SORT_BY_NAME(SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal)) '
                    'SORT_BY_NAME(SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal.*)) '
                    'SORT_BY_NAME(SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text)) '
                    'SORT_BY_NAME(SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*))'
                    ')')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')], keep=False, sort=('name', 'name'))
        self.assertEqual(expected, str(desc))

        expected = ('*libfreertos.a:croutine.*('
                    'SORT_BY_ALIGNMENT(SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal)) '
                    'SORT_BY_ALIGNMENT(SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal.*)) '
                    'SORT_BY_ALIGNMENT(SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text)) '
                    'SORT_BY_ALIGNMENT(SORT_BY_NAME(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*))'
                    ')')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')], keep=False, sort=('alignment', 'name'))
        self.assertEqual(expected, str(desc))

        expected = ('*libfreertos.a:croutine.*('
                    'SORT_BY_ALIGNMENT(SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal)) '
                    'SORT_BY_ALIGNMENT(SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .literal.*)) '
                    'SORT_BY_ALIGNMENT(SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text)) '
                    'SORT_BY_ALIGNMENT(SORT_BY_ALIGNMENT(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*))'
                    ')')
        desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')], keep=False, sort=('alignment', 'alignment'))
        self.assertEqual(expected, str(desc))
Exemple #10
0
    def test_keep(self):
        # Test KEEP
        expected = 'KEEP(*libfreertos.a:croutine.*( ))'

        desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), [], keep=True)
        self.assertEqual(expected, str(desc))
Exemple #11
0
    def test_empty_sections(self):
        # Test empty sections
        expected = '*libfreertos.a:croutine.*( )'

        desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), [])
        self.assertEqual(expected, str(desc))
Exemple #12
0
    def get_node_output_commands(self):
        commands = collections.defaultdict(list)

        for sections in self.get_output_sections():
            placement = self.placements[sections]
            if placement.is_significant():
                assert (placement.node == self)

                keep = False
                sort = None
                surround_type = []

                placement_flags = placement.flags if placement.flags is not None else []

                for flag in placement_flags:
                    if isinstance(flag, Mapping.Keep):
                        keep = True
                    elif isinstance(flag, Mapping.Sort):
                        sort = (flag.first, flag.second)
                    else:  # SURROUND or ALIGN
                        surround_type.append(flag)

                for flag in surround_type:
                    if flag.pre:
                        if isinstance(flag, Mapping.Surround):
                            commands[placement.target].append(
                                SymbolAtAddress('_%s_start' % flag.symbol))
                        else:  # ALIGN
                            commands[placement.target].append(
                                AlignAtAddress(flag.alignment))

                # This is for expanded object node and symbol node placements without checking for
                # the type.
                placement_sections = frozenset(placement.sections)
                command_sections = sections if sections == placement_sections else placement_sections

                command = InputSectionDesc(
                    placement.node.entity, command_sections,
                    [e.node.entity for e in placement.exclusions], keep, sort)
                commands[placement.target].append(command)

                # Generate commands for intermediate, non-explicit exclusion placements here, so that they can be enclosed by
                # flags that affect the parent placement.
                for subplacement in placement.subplacements:
                    if not subplacement.flags and not subplacement.explicit:
                        command = InputSectionDesc(
                            subplacement.node.entity, subplacement.sections,
                            [e.node.entity
                             for e in subplacement.exclusions], keep, sort)
                        commands[placement.target].append(command)

                for flag in surround_type:
                    if flag.post:
                        if isinstance(flag, Mapping.Surround):
                            commands[placement.target].append(
                                SymbolAtAddress('_%s_end' % flag.symbol))
                        else:  # ALIGN
                            commands[placement.target].append(
                                AlignAtAddress(flag.alignment))

        return commands