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
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.
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
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.
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(-)
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>
37 diff --git a/gold/merge.cc b/gold/merge.cc
38 index de00ee9ae9..d7de11789f 100644
41 @@ -440,9 +440,11 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
43 section_size_type sec_len;
45 + uint64_t addralign = this->addralign();
46 const unsigned char* pdata = object->decompressed_section_contents(shndx,
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
57 uintptr_t init_align_modulo = (reinterpret_cast<uintptr_t>(pdata)
58 - & (this->addralign() - 1));
60 bool has_misaligned_strings = false;
63 @@ -503,7 +505,7 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
65 // Within merge input section each string must be aligned.
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;
72 diff --git a/gold/object.cc b/gold/object.cc
73 index 374340fa16..711793e5e4 100644
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;
83 // Skip over the ".zdebug" prefix.
85 uncompressed_size = get_uncompressed_size(contents, len);
86 + info.addralign = shdr.get_sh_addralign();
90 @@ -763,8 +765,8 @@ build_compressed_section_map(
92 elfcpp::Chdr<size, big_endian> chdr(contents);
93 uncompressed_size = chdr.get_ch_size();
94 + info.addralign = chdr.get_ch_addralign();
96 - Compressed_section_info info;
97 info.size = convert_to_section_size_type(uncompressed_size);
98 info.flag = shdr.get_sh_flags();
100 @@ -3060,7 +3062,8 @@ const unsigned char*
101 Object::decompressed_section_contents(
103 section_size_type* plen,
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(
112 *plen = uncompressed_size;
114 + if (palign != NULL)
115 + *palign = p->second.addralign;
116 return p->second.contents;
119 @@ -3108,6 +3113,8 @@ Object::decompressed_section_contents(
120 // once in this pass.
121 *plen = uncompressed_size;
123 + if (palign != NULL)
124 + *palign = p->second.addralign;
125 return uncompressed_data;
128 diff --git a/gold/object.h b/gold/object.h
129 index 0b786a5471..b99548463d 100644
132 @@ -373,6 +373,7 @@ struct Compressed_section_info
134 section_size_type size;
135 elfcpp::Elf_Xword flag;
136 + uint64_t addralign;
137 const unsigned char* contents;
139 typedef std::map<unsigned int, Compressed_section_info> Compressed_section_map;
140 @@ -808,7 +809,8 @@ class Object
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
148 if (this->compressed_sections_ == NULL)
150 @@ -818,6 +820,8 @@ class Object
152 if (uncompressed_size != NULL)
153 *uncompressed_size = p->second.size;
154 + if (palign != NULL)
155 + *palign = p->second.addralign;
159 @@ -828,7 +832,7 @@ class Object
162 decompressed_section_contents(unsigned int shndx, section_size_type* plen,
164 + bool* is_cached, uint64_t* palign = NULL);
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
172 @@ -2448,7 +2448,13 @@ Output_section::add_input_section(Layout* layout,
173 unsigned int reloc_shndx,
174 bool have_sections_script)
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,
181 + input_section_size = uncompressed_size;
183 if ((addralign & (addralign - 1)) != 0)
185 object->error(_("invalid alignment %lu for section \"%s\""),
186 @@ -2498,11 +2504,6 @@ Output_section::add_input_section(Layout* layout,
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;
195 off_t offset_in_section;
197 if (this->has_fixed_layout())