]> code.ossystems Code Review - openembedded-core.git/blob
1f072a605798b0bb6f33102032e0d41f74b0b397
[openembedded-core.git] /
1 From 0261ec511ac07177fa488133e0bb3c03860977b3 Mon Sep 17 00:00:00 2001
2 From: "H.J. Lu" <hjl.tools@gmail.com>
3 Date: Sun, 2 Dec 2018 05:42:36 -0800
4 Subject: [PATCH 2/2] gold: Get alignment of uncompressed section from
5  ch_addralign
6
7 The ELF compression header has a field (ch_addralign) that is set to
8 the alignment of the uncompressed section. This way the section itself
9 can have a different alignment than the decompressed section.  Update
10 decompress_input_section to get alignment of the decompressed section
11 and use it when merging decompressed strings.
12
13         PR binutils/23919
14         * merge.cc (Output_merge_string<Char_type>::do_add_input_section):
15         Get addralign from decompressed_section_contents.
16         * object.cc (build_compressed_section_map): Set info.addralign.
17         (Object::decompressed_section_contents): Add a palign
18         argument and store p->second.addralign in *palign if it isn't
19         NULL.
20         * object.h (Compressed_section_info): Add addralign.
21         (section_is_compressed): Add a palign argument, default it
22         to NULL, store p->second.addralign in *palign if it isn't NULL.
23         (Object::decompressed_section_contents): Likewise.
24         * output.cc (Output_section::add_input_section): Get addralign
25         from section_is_compressed.
26 ---
27  gold/merge.cc  |  8 +++++---
28  gold/object.cc | 11 +++++++++--
29  gold/object.h  |  8 ++++++--
30  gold/output.cc | 11 ++++++-----
31  4 files changed, 26 insertions(+), 12 deletions(-)
32
33 Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5f6c22aee74f17393b82934a5682d985672e011a]
34 Signed-off-by: Khem Raj <raj.khem@gmail.com>
35
36
37 diff --git a/gold/merge.cc b/gold/merge.cc
38 index de00ee9ae9..d7de11789f 100644
39 --- a/gold/merge.cc
40 +++ b/gold/merge.cc
41 @@ -440,9 +440,11 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
42  {
43    section_size_type sec_len;
44    bool is_new;
45 +  uint64_t addralign = this->addralign();
46    const unsigned char* pdata = object->decompressed_section_contents(shndx,
47                                                                      &sec_len,
48 -                                                                    &is_new);
49 +                                                                    &is_new,
50 +                                                                    &addralign);
51  
52    const Char_type* p = reinterpret_cast<const Char_type*>(pdata);
53    const Char_type* pend = p + sec_len / sizeof(Char_type);
54 @@ -494,7 +496,7 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
55    // aligned, so each string within the section must retain the same
56    // modulo.
57    uintptr_t init_align_modulo = (reinterpret_cast<uintptr_t>(pdata)
58 -                                & (this->addralign() - 1));
59 +                                & (addralign - 1));
60    bool has_misaligned_strings = false;
61  
62    while (p < pend)
63 @@ -503,7 +505,7 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
64  
65        // Within merge input section each string must be aligned.
66        if (len != 0
67 -         && ((reinterpret_cast<uintptr_t>(p) & (this->addralign() - 1))
68 +         && ((reinterpret_cast<uintptr_t>(p) & (addralign - 1))
69               != init_align_modulo))
70           has_misaligned_strings = true;
71  
72 diff --git a/gold/object.cc b/gold/object.cc
73 index 374340fa16..711793e5e4 100644
74 --- a/gold/object.cc
75 +++ b/gold/object.cc
76 @@ -751,11 +751,13 @@ build_compressed_section_map(
77               const unsigned char* contents =
78                   obj->section_contents(i, &len, false);
79               uint64_t uncompressed_size;
80 +             Compressed_section_info info;
81               if (is_zcompressed)
82                 {
83                   // Skip over the ".zdebug" prefix.
84                   name += 7;
85                   uncompressed_size = get_uncompressed_size(contents, len);
86 +                 info.addralign = shdr.get_sh_addralign();
87                 }
88               else
89                 {
90 @@ -763,8 +765,8 @@ build_compressed_section_map(
91                   name += 6;
92                   elfcpp::Chdr<size, big_endian> chdr(contents);
93                   uncompressed_size = chdr.get_ch_size();
94 +                 info.addralign = chdr.get_ch_addralign();
95                 }
96 -             Compressed_section_info info;
97               info.size = convert_to_section_size_type(uncompressed_size);
98               info.flag = shdr.get_sh_flags();
99               info.contents = NULL;
100 @@ -3060,7 +3062,8 @@ const unsigned char*
101  Object::decompressed_section_contents(
102      unsigned int shndx,
103      section_size_type* plen,
104 -    bool* is_new)
105 +    bool* is_new,
106 +    uint64_t* palign)
107  {
108    section_size_type buffer_size;
109    const unsigned char* buffer = this->do_section_contents(shndx, &buffer_size,
110 @@ -3087,6 +3090,8 @@ Object::decompressed_section_contents(
111      {
112        *plen = uncompressed_size;
113        *is_new = false;
114 +      if (palign != NULL)
115 +       *palign = p->second.addralign;
116        return p->second.contents;
117      }
118  
119 @@ -3108,6 +3113,8 @@ Object::decompressed_section_contents(
120    // once in this pass.
121    *plen = uncompressed_size;
122    *is_new = true;
123 +  if (palign != NULL)
124 +    *palign = p->second.addralign;
125    return uncompressed_data;
126  }
127  
128 diff --git a/gold/object.h b/gold/object.h
129 index 0b786a5471..b99548463d 100644
130 --- a/gold/object.h
131 +++ b/gold/object.h
132 @@ -373,6 +373,7 @@ struct Compressed_section_info
133  {
134    section_size_type size;
135    elfcpp::Elf_Xword flag;
136 +  uint64_t addralign;
137    const unsigned char* contents;
138  };
139  typedef std::map<unsigned int, Compressed_section_info> Compressed_section_map;
140 @@ -808,7 +809,8 @@ class Object
141  
142    bool
143    section_is_compressed(unsigned int shndx,
144 -                       section_size_type* uncompressed_size) const
145 +                       section_size_type* uncompressed_size,
146 +                       elfcpp::Elf_Xword* palign = NULL) const
147    {
148      if (this->compressed_sections_ == NULL)
149        return false;
150 @@ -818,6 +820,8 @@ class Object
151        {
152         if (uncompressed_size != NULL)
153           *uncompressed_size = p->second.size;
154 +       if (palign != NULL)
155 +         *palign = p->second.addralign;
156         return true;
157        }
158      return false;
159 @@ -828,7 +832,7 @@ class Object
160    // by the caller.
161    const unsigned char*
162    decompressed_section_contents(unsigned int shndx, section_size_type* plen,
163 -                               bool* is_cached);
164 +                               bool* is_cached, uint64_t* palign = NULL);
165  
166    // Discard any buffers of decompressed sections.  This is done
167    // at the end of the Add_symbols task.
168 diff --git a/gold/output.cc b/gold/output.cc
169 index 1701db1c99..75ac3bcf97 100644
170 --- a/gold/output.cc
171 +++ b/gold/output.cc
172 @@ -2448,7 +2448,13 @@ Output_section::add_input_section(Layout* layout,
173                                   unsigned int reloc_shndx,
174                                   bool have_sections_script)
175  {
176 +  section_size_type input_section_size = shdr.get_sh_size();
177 +  section_size_type uncompressed_size;
178    elfcpp::Elf_Xword addralign = shdr.get_sh_addralign();
179 +  if (object->section_is_compressed(shndx, &uncompressed_size,
180 +                                   &addralign))
181 +    input_section_size = uncompressed_size;
182 +
183    if ((addralign & (addralign - 1)) != 0)
184      {
185        object->error(_("invalid alignment %lu for section \"%s\""),
186 @@ -2498,11 +2504,6 @@ Output_section::add_input_section(Layout* layout,
187         }
188      }
189  
190 -  section_size_type input_section_size = shdr.get_sh_size();
191 -  section_size_type uncompressed_size;
192 -  if (object->section_is_compressed(shndx, &uncompressed_size))
193 -    input_section_size = uncompressed_size;
194 -
195    off_t offset_in_section;
196  
197    if (this->has_fixed_layout())
198 -- 
199 2.20.1
200