Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 4c5fe98

Browse files
enh-googleGerrit Code Review
authored andcommitted
Merge "linker: use %m in error messages." into main
2 parents 0347038 + f5e21d9 commit 4c5fe98

File tree

6 files changed

+23
-31
lines changed

6 files changed

+23
-31
lines changed

linker/linker.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static bool realpath_fd(int fd, std::string* realpath) {
387387
auto length = readlink(proc_self_fd, buf, sizeof(buf));
388388
if (length == -1) {
389389
if (!is_first_stage_init()) {
390-
PRINT("readlink(\"%s\") failed: %s [fd=%d]", proc_self_fd, strerror(errno), fd);
390+
PRINT("readlink(\"%s\" [fd=%d]) failed: %m", proc_self_fd, fd);
391391
}
392392
return false;
393393
}
@@ -1185,7 +1185,7 @@ static bool load_library(android_namespace_t* ns,
11851185

11861186
struct stat file_stat;
11871187
if (TEMP_FAILURE_RETRY(fstat(task->get_fd(), &file_stat)) != 0) {
1188-
DL_OPEN_ERR("unable to stat file for the library \"%s\": %s", name, strerror(errno));
1188+
DL_OPEN_ERR("unable to stat file for the library \"%s\": %m", name);
11891189
return false;
11901190
}
11911191
if (file_offset >= file_stat.st_size) {
@@ -1215,7 +1215,7 @@ static bool load_library(android_namespace_t* ns,
12151215

12161216
struct statfs fs_stat;
12171217
if (TEMP_FAILURE_RETRY(fstatfs(task->get_fd(), &fs_stat)) != 0) {
1218-
DL_OPEN_ERR("unable to fstatfs file for the library \"%s\": %s", name, strerror(errno));
1218+
DL_OPEN_ERR("unable to fstatfs file for the library \"%s\": %m", name);
12191219
return false;
12201220
}
12211221

@@ -3364,7 +3364,7 @@ bool soinfo::link_image(const SymbolLookupList& lookup_list, soinfo* local_group
33643364
get_realpath());
33653365
add_dlwarning(get_realpath(), "text relocations");
33663366
if (phdr_table_unprotect_segments(phdr, phnum, load_bias, should_pad_segments_) < 0) {
3367-
DL_ERR("can't unprotect loadable segments for \"%s\": %s", get_realpath(), strerror(errno));
3367+
DL_ERR("can't unprotect loadable segments for \"%s\": %m", get_realpath());
33683368
return false;
33693369
}
33703370
}
@@ -3380,8 +3380,7 @@ bool soinfo::link_image(const SymbolLookupList& lookup_list, soinfo* local_group
33803380
if (has_text_relocations) {
33813381
// All relocations are done, we can protect our segments back to read-only.
33823382
if (phdr_table_protect_segments(phdr, phnum, load_bias, should_pad_segments_) < 0) {
3383-
DL_ERR("can't protect segments for \"%s\": %s",
3384-
get_realpath(), strerror(errno));
3383+
DL_ERR("can't protect segments for \"%s\": %m", get_realpath());
33853384
return false;
33863385
}
33873386
}
@@ -3397,15 +3396,13 @@ bool soinfo::link_image(const SymbolLookupList& lookup_list, soinfo* local_group
33973396
if (extinfo && (extinfo->flags & ANDROID_DLEXT_WRITE_RELRO)) {
33983397
if (phdr_table_serialize_gnu_relro(phdr, phnum, load_bias,
33993398
extinfo->relro_fd, relro_fd_offset) < 0) {
3400-
DL_ERR("failed serializing GNU RELRO section for \"%s\": %s",
3401-
get_realpath(), strerror(errno));
3399+
DL_ERR("failed serializing GNU RELRO section for \"%s\": %m", get_realpath());
34023400
return false;
34033401
}
34043402
} else if (extinfo && (extinfo->flags & ANDROID_DLEXT_USE_RELRO)) {
34053403
if (phdr_table_map_gnu_relro(phdr, phnum, load_bias,
34063404
extinfo->relro_fd, relro_fd_offset) < 0) {
3407-
DL_ERR("failed mapping GNU RELRO section for \"%s\": %s",
3408-
get_realpath(), strerror(errno));
3405+
DL_ERR("failed mapping GNU RELRO section for \"%s\": %m", get_realpath());
34093406
return false;
34103407
}
34113408
}
@@ -3418,8 +3415,7 @@ bool soinfo::link_image(const SymbolLookupList& lookup_list, soinfo* local_group
34183415

34193416
bool soinfo::protect_relro() {
34203417
if (phdr_table_protect_gnu_relro(phdr, phnum, load_bias, should_pad_segments_) < 0) {
3421-
DL_ERR("can't enable GNU RELRO protection for \"%s\": %s",
3422-
get_realpath(), strerror(errno));
3418+
DL_ERR("can't enable GNU RELRO protection for \"%s\": %m", get_realpath());
34233419
return false;
34243420
}
34253421
return true;

linker/linker_config.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,10 @@ static bool parse_config_file(const char* ld_config_file_path,
254254
// the failure with INFO rather than DL_WARN. e.g. A binary in
255255
// /data/local/tmp may attempt to stat /postinstall. See
256256
// http://b/120996057.
257-
INFO("%s:%zd: warning: path \"%s\" couldn't be resolved: %s",
257+
INFO("%s:%zd: warning: path \"%s\" couldn't be resolved: %m",
258258
ld_config_file_path,
259259
cp.lineno(),
260-
value.c_str(),
261-
strerror(errno));
260+
value.c_str());
262261
resolved_path = value;
263262
}
264263

linker/linker_main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ static ExecutableInfo get_executable_info(const char* arg_path) {
234234
if (TEMP_FAILURE_RETRY(stat(exe_path, &result.file_stat) == -1)) {
235235
// Fallback to argv[0] for the case where /proc isn't available
236236
if (TEMP_FAILURE_RETRY(stat(arg_path, &result.file_stat) == -1)) {
237-
async_safe_fatal("unable to stat either \"/proc/self/exe\" or \"%s\": %s",
238-
arg_path, strerror(errno));
237+
async_safe_fatal("unable to stat either \"/proc/self/exe\" or \"%s\": %m", arg_path);
239238
}
240239
exe_path = arg_path;
241240
}

linker/linker_phdr.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ bool ElfReader::ReadElfHeader() {
234234
#endif
235235

236236
if (!file_fragment_.Map(fd_, file_offset_, 0, map_size)) {
237-
DL_ERR("\"%s\" header mmap failed: %s", name_.c_str(), strerror(errno));
237+
DL_ERR("\"%s\" header mmap failed: %m", name_.c_str());
238238
return false;
239239
}
240240

@@ -389,7 +389,7 @@ bool ElfReader::ReadProgramHeaders() {
389389

390390
void* phdr_data = MapData(&phdr_fragment_, header_.e_phoff, size);
391391
if (phdr_data == nullptr) {
392-
DL_ERR("\"%s\" phdr mmap failed: %s", name_.c_str(), strerror(errno));
392+
DL_ERR("\"%s\" phdr mmap failed: %m", name_.c_str());
393393
return false;
394394
}
395395

@@ -416,7 +416,7 @@ bool ElfReader::ReadSectionHeaders() {
416416

417417
void* shdr_data = MapData(&shdr_fragment_, header_.e_shoff, size);
418418
if (shdr_data == nullptr) {
419-
DL_ERR("\"%s\" shdr mmap failed: %s", name_.c_str(), strerror(errno));
419+
DL_ERR("\"%s\" shdr mmap failed: %m", name_.c_str());
420420
return false;
421421
}
422422

@@ -510,7 +510,7 @@ bool ElfReader::ReadDynamicSection() {
510510

511511
void* dynamic_data = MapData(&dynamic_fragment_, dynamic_shdr->sh_offset, dynamic_shdr->sh_size);
512512
if (dynamic_data == nullptr) {
513-
DL_ERR("\"%s\" dynamic section mmap failed: %s", name_.c_str(), strerror(errno));
513+
DL_ERR("\"%s\" dynamic section mmap failed: %m", name_.c_str());
514514
return false;
515515
}
516516

@@ -524,7 +524,7 @@ bool ElfReader::ReadDynamicSection() {
524524

525525
void* strtab_data = MapData(&strtab_fragment_, strtab_shdr->sh_offset, strtab_shdr->sh_size);
526526
if (strtab_data == nullptr) {
527-
DL_ERR("\"%s\" strtab section mmap failed: %s", name_.c_str(), strerror(errno));
527+
DL_ERR("\"%s\" strtab section mmap failed: %m", name_.c_str());
528528
return false;
529529
}
530530

@@ -923,7 +923,7 @@ bool ElfReader::LoadSegments() {
923923
fd_,
924924
file_offset_ + file_page_start);
925925
if (seg_addr == MAP_FAILED) {
926-
DL_ERR("couldn't map \"%s\" segment %zd: %s", name_.c_str(), i, strerror(errno));
926+
DL_ERR("couldn't map \"%s\" segment %zd: %m", name_.c_str(), i);
927927
return false;
928928
}
929929

@@ -984,7 +984,7 @@ bool ElfReader::LoadSegments() {
984984
-1,
985985
0);
986986
if (zeromap == MAP_FAILED) {
987-
DL_ERR("couldn't zero fill \"%s\" gap: %s", name_.c_str(), strerror(errno));
987+
DL_ERR("couldn't zero fill \"%s\" gap: %m", name_.c_str());
988988
return false;
989989
}
990990

linker/linker_relocate.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ static bool process_relocation_impl(Relocator& relocator, const rel_t& reloc) {
189189
if (phdr_table_protect_segments(relocator.si->phdr, relocator.si->phnum,
190190
relocator.si->load_bias,
191191
relocator.si->should_pad_segments()) < 0) {
192-
DL_ERR("can't protect segments for \"%s\": %s",
193-
relocator.si->get_realpath(), strerror(errno));
192+
DL_ERR("can't protect segments for \"%s\": %m", relocator.si->get_realpath());
194193
return false;
195194
}
196195
return true;
@@ -200,8 +199,8 @@ static bool process_relocation_impl(Relocator& relocator, const rel_t& reloc) {
200199
if (phdr_table_unprotect_segments(relocator.si->phdr, relocator.si->phnum,
201200
relocator.si->load_bias,
202201
relocator.si->should_pad_segments()) < 0) {
203-
DL_ERR("can't unprotect loadable segments for \"%s\": %s",
204-
relocator.si->get_realpath(), strerror(errno));
202+
DL_ERR("can't unprotect loadable segments for \"%s\": %m",
203+
relocator.si->get_realpath());
205204
return false;
206205
}
207206
return true;

linker/linker_utils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ std::string resolve_path(const std::string& path) {
207207
if (realpath(original_path, resolved_path) != nullptr) {
208208
struct stat s;
209209
if (stat(resolved_path, &s) == -1) {
210-
DL_WARN("Warning: cannot stat file \"%s\": %s (ignoring)", resolved_path, strerror(errno));
210+
DL_WARN("Warning: cannot stat file \"%s\": %m (ignoring)", resolved_path);
211211
return "";
212212
}
213213
if (!S_ISDIR(s.st_mode)) {
@@ -226,8 +226,7 @@ std::string resolve_path(const std::string& path) {
226226
std::string entry_path;
227227
if (parse_zip_path(normalized_path.c_str(), &zip_path, &entry_path)) {
228228
if (realpath(zip_path.c_str(), resolved_path) == nullptr) {
229-
DL_WARN("Warning: unable to resolve \"%s\": %s (ignoring)",
230-
zip_path.c_str(), strerror(errno));
229+
DL_WARN("Warning: unable to resolve \"%s\": %m (ignoring)", zip_path.c_str());
231230
return "";
232231
}
233232

0 commit comments

Comments
 (0)