1 /* Section hash table implementation.
2 Copyright (C) 2001, 2002, 2005 Red Hat, Inc.
3 This file is part of Red Hat elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2001.
5
6 Red Hat elfutils is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by the
8 Free Software Foundation; version 2 of the License.
9
10 Red Hat elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with Red Hat elfutils; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
18
19 Red Hat elfutils is an included package of the Open Invention Network.
20 An included package of the Open Invention Network is a package for which
21 Open Invention Network licensees cross-license their patents. No patent
22 license is granted, either expressly or impliedly, by designation as an
23 included package. Should you wish to participate in the Open Invention
24 Network licensing program, please visit www.openinventionnetwork.com
25 <http://www.openinventionnetwork.com>. */
26
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30
31 #include <string.h>
32
33 #include <elf-knowledge.h>
34 #include <ld.h>
35
36
37 /* Comparison function for sections. */
38 static int
scnhead_compare(struct scnhead * one,struct scnhead * two)39 scnhead_compare (struct scnhead *one, struct scnhead *two)
40 {
41 int result = strcmp (one->name, two->name);
42
43 if (result == 0)
44 {
45 result = one->type - two->type;
46
47 if (result == 0)
48 {
49 GElf_Sxword diff = (SH_FLAGS_IMPORTANT (one->flags)
50 - SH_FLAGS_IMPORTANT (two->flags));
51 result = diff < 0 ? -1 : diff == 0 ? 0 : 1;
52
53 if (result == 0)
54 {
55 result = one->entsize - two->entsize;
56
57 if (result == 0)
58 {
59 result = (one->grp_signature == NULL
60 ? (two->grp_signature == NULL ? 0 : -1)
61 : (two->grp_signature == NULL
62 ? 1 : strcmp (one->grp_signature,
63 two->grp_signature)));
64
65 if (result == 0)
66 result = one->kind - two->kind;
67 }
68 }
69 }
70 }
71
72 return result;
73 }
74
75 /* Definitions for the section hash table. */
76 #define TYPE struct scnhead *
77 #define NAME ld_section_tab
78 #define ITERATE 1
79 #define COMPARE(a, b) scnhead_compare (a, b)
80
81 #include "../lib/dynamicsizehash.c"
82