From c533f813a2c1392f51f8a0f803ab41775817d530 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 27 May 2009 14:32:11 +0000 Subject: [PATCH] Normalized the FATAL messages. The image path is always printed, now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30878 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/runtime_loader/elf.cpp | 5 +-- .../runtime_loader/elf_haiku_version.cpp | 19 ++++++---- src/system/runtime_loader/elf_load_image.cpp | 37 ++++++++++--------- .../runtime_loader/elf_symbol_lookup.cpp | 21 ++++++----- src/system/runtime_loader/elf_versioning.cpp | 15 ++++---- 5 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/system/runtime_loader/elf.cpp b/src/system/runtime_loader/elf.cpp index 82469bf411..d80bdbcf59 100644 --- a/src/system/runtime_loader/elf.cpp +++ b/src/system/runtime_loader/elf.cpp @@ -110,7 +110,7 @@ load_immediate_dependencies(image_t *image) image->needed = (image_t**)malloc(image->num_needed * sizeof(image_t *)); if (image->needed == NULL) { - FATAL("failed to allocate needed struct\n"); + FATAL("%s: Failed to allocate needed struct\n", image->path); KTRACE("rld: load_dependencies(\"%s\", id: %ld) failed: no memory", image->name, image->id); return B_NO_MEMORY; @@ -207,8 +207,7 @@ relocate_image(image_t *rootImage, image_t *image) { status_t status = arch_relocate_image(rootImage, image); if (status < B_OK) { - FATAL("troubles relocating: 0x%lx (image: %s, %s)\n", status, - image->path, image->name); + FATAL("%s: Troubles relocating: %s\n", image->path, strerror(status)); return status; } diff --git a/src/system/runtime_loader/elf_haiku_version.cpp b/src/system/runtime_loader/elf_haiku_version.cpp index 2d9952d816..0646eb850f 100644 --- a/src/system/runtime_loader/elf_haiku_version.cpp +++ b/src/system/runtime_loader/elf_haiku_version.cpp @@ -24,14 +24,16 @@ analyze_object_gcc_version(int fd, image_t* image, Elf32_Ehdr& eheader, int32 sheaderSize, char* buffer, size_t bufferSize) { if (sheaderSize > (int)bufferSize) { - FATAL("Cannot handle section headers bigger than %lu\n", bufferSize); + FATAL("%s: Cannot handle section headers bigger than %lu bytes\n", + image->path, bufferSize); return false; } // read section headers ssize_t length = _kern_read(fd, eheader.e_shoff, buffer, sheaderSize); if (length != sheaderSize) { - FATAL("Could not read section headers: %s\n", strerror(length)); + FATAL("%s: Could not read section headers: %s\n", image->path, + strerror(length)); return false; } @@ -40,7 +42,8 @@ analyze_object_gcc_version(int fd, image_t* image, Elf32_Ehdr& eheader, = (Elf32_Shdr*)(buffer + eheader.e_shstrndx * eheader.e_shentsize); if (sheaderSize + sectionHeader->sh_size > bufferSize) { - FATAL("Buffer not big enough for section string section\n"); + FATAL("%s: Buffer not big enough for section string section\n", + image->path); return false; } @@ -48,7 +51,8 @@ analyze_object_gcc_version(int fd, image_t* image, Elf32_Ehdr& eheader, length = _kern_read(fd, sectionHeader->sh_offset, sectionStrings, sectionHeader->sh_size); if (length != (int)sectionHeader->sh_size) { - FATAL("Could not read section string section: %s\n", strerror(length)); + FATAL("%s: Could not read section string section: %s\n", image->path, + strerror(length)); return false; } @@ -67,7 +71,7 @@ analyze_object_gcc_version(int fd, image_t* image, Elf32_Ehdr& eheader, } if (commentSize == 0) { - FATAL("Could not find .comment section\n"); + FATAL("%s: Could not find .comment section\n", image->path); return false; } @@ -77,7 +81,8 @@ analyze_object_gcc_version(int fd, image_t* image, Elf32_Ehdr& eheader, length = _kern_read(fd, commentOffset, buffer, commentSize); if (length != (int)commentSize) { - FATAL("Could not read .comment section: %s\n", strerror(length)); + FATAL("%s: Could not read .comment section: %s\n", image->path, + strerror(length)); return false; } @@ -218,7 +223,7 @@ analyze_image_haiku_version_and_abi(int fd, image_t* image, Elf32_Ehdr& eheader, // version. if (!analyze_object_gcc_version(fd, image, eheader, sheaderSize, buffer, bufferSize)) { - FATAL("Failed to get gcc version for %s\n", image->path); + FATAL("%s: Failed to get gcc version.\n", image->path); // not really fatal, actually // assume ancient BeOS diff --git a/src/system/runtime_loader/elf_load_image.cpp b/src/system/runtime_loader/elf_load_image.cpp index 05d6da6fa5..5a340bcd8a 100644 --- a/src/system/runtime_loader/elf_load_image.cpp +++ b/src/system/runtime_loader/elf_load_image.cpp @@ -34,7 +34,7 @@ get_program_path() static int32 -count_regions(char const* buff, int phnum, int phentsize) +count_regions(const char* imagePath, char const* buff, int phnum, int phentsize) { struct Elf32_Phdr* pheaders; int32 count = 0; @@ -78,8 +78,8 @@ count_regions(char const* buff, int phnum, int phentsize) // we don't use it break; default: - FATAL("unhandled pheader type in count 0x%lx\n", - pheaders->p_type); + FATAL("%s: Unhandled pheader type in count 0x%lx\n", + imagePath, pheaders->p_type); return B_BAD_DATA; } } @@ -194,8 +194,8 @@ parse_program_headers(image_t* image, char* buff, int phnum, int phentsize) // we don't use it break; default: - FATAL("unhandled pheader type in parse 0x%lx\n", - pheader->p_type); + FATAL("%s: Unhandled pheader type in parse 0x%lx\n", + image->path, pheader->p_type); return B_BAD_DATA; } } @@ -400,7 +400,7 @@ load_image(char const* name, image_type type, const char* rpath, fd = open_executable(path, type, rpath, get_program_path(), sSearchPathSubDir); if (fd < 0) { - FATAL("cannot open file %s\n", name); + FATAL("Cannot open file %s: %s\n", name, strerror(fd)); KTRACE("rld: load_container(\"%s\"): failed to open file", name); return fd; } @@ -428,42 +428,44 @@ load_image(char const* name, image_type type, const char* rpath, length = _kern_read(fd, 0, &eheader, sizeof(eheader)); if (length != sizeof(eheader)) { status = B_NOT_AN_EXECUTABLE; - FATAL("troubles reading ELF header\n"); + FATAL("%s: Troubles reading ELF header\n", path); goto err1; } status = parse_elf_header(&eheader, &pheaderSize, &sheaderSize); if (status < B_OK) { - FATAL("incorrect ELF header\n"); + FATAL("%s: Incorrect ELF header\n", path); goto err1; } // ToDo: what to do about this restriction?? if (pheaderSize > (int)sizeof(pheaderBuffer)) { - FATAL("Cannot handle program headers bigger than %lu\n", - sizeof(pheaderBuffer)); + FATAL("%s: Cannot handle program headers bigger than %lu\n", + path, sizeof(pheaderBuffer)); status = B_UNSUPPORTED; goto err1; } length = _kern_read(fd, eheader.e_phoff, pheaderBuffer, pheaderSize); if (length != pheaderSize) { - FATAL("Could not read program headers: %s\n", strerror(length)); + FATAL("%s: Could not read program headers: %s\n", path, + strerror(length)); status = B_BAD_DATA; goto err1; } - numRegions = count_regions(pheaderBuffer, eheader.e_phnum, + numRegions = count_regions(path, pheaderBuffer, eheader.e_phnum, eheader.e_phentsize); if (numRegions <= 0) { - FATAL("Troubles parsing Program headers, numRegions = %ld\n", numRegions); + FATAL("%s: Troubles parsing Program headers, numRegions = %ld\n", + path, numRegions); status = B_BAD_DATA; goto err1; } image = create_image(name, path, numRegions); if (image == NULL) { - FATAL("Failed to allocate image_t object\n"); + FATAL("%s: Failed to allocate image_t object\n", path); status = B_NO_MEMORY; goto err1; } @@ -474,20 +476,21 @@ load_image(char const* name, image_type type, const char* rpath, goto err2; if (!assert_dynamic_loadable(image)) { - FATAL("Dynamic segment must be loadable (implementation restriction)\n"); + FATAL("%s: Dynamic segment must be loadable (implementation " + "restriction)\n", image->path); status = B_UNSUPPORTED; goto err2; } status = map_image(fd, path, image, type == B_APP_IMAGE); if (status < B_OK) { - FATAL("Could not map image: %s\n", strerror(status)); + FATAL("%s: Could not map image: %s\n", image->path, strerror(status)); status = B_ERROR; goto err2; } if (!parse_dynamic_segment(image)) { - FATAL("Troubles handling dynamic section\n"); + FATAL("%s: Troubles handling dynamic section\n", image->path); status = B_BAD_DATA; goto err3; } diff --git a/src/system/runtime_loader/elf_symbol_lookup.cpp b/src/system/runtime_loader/elf_symbol_lookup.cpp index 3ee0f453f8..3ec8cd1839 100644 --- a/src/system/runtime_loader/elf_symbol_lookup.cpp +++ b/src/system/runtime_loader/elf_symbol_lookup.cpp @@ -389,20 +389,20 @@ resolve_symbol(image_t* rootImage, image_t* image, struct Elf32_Sym* sym, if (location == NULL) { switch (lookupError) { case ERROR_NO_SYMBOL: - FATAL("elf_resolve_symbol: could not resolve symbol " - "'%s'\n", symName); + FATAL("%s: Could not resolve symbol '%s'\n", + image->path, symName); break; case ERROR_WRONG_TYPE: - FATAL("elf_resolve_symbol: found symbol '%s' in shared " - "image but wrong type\n", symName); + FATAL("%s: Found symbol '%s' in shared image but wrong " + "type\n", image->path, symName); break; case ERROR_NOT_EXPORTED: - FATAL("elf_resolve_symbol: found symbol '%s', but not " - "exported\n", symName); + FATAL("%s: Found symbol '%s', but not exported\n", + image->path, symName); break; case ERROR_UNPATCHED: - FATAL("elf_resolve_symbol: found symbol '%s', but was " - "hidden by symbol patchers\n", symName); + FATAL("%s: Found symbol '%s', but was hidden by symbol " + "patchers\n", image->path, symName); break; } @@ -421,8 +421,9 @@ resolve_symbol(image_t* rootImage, image_t* image, struct Elf32_Sym* sym, return B_NO_ERROR; case SHN_COMMON: - // ToDo: finish this - FATAL("elf_resolve_symbol: COMMON symbol, finish me!\n"); + // TODO: finish this + FATAL("%s: elf_resolve_symbol: COMMON symbol, finish me!\n", + image->path); return B_ERROR; //ERR_NOT_IMPLEMENTED_YET; default: diff --git a/src/system/runtime_loader/elf_versioning.cpp b/src/system/runtime_loader/elf_versioning.cpp index 045dd197fa..1cdd3b75e7 100644 --- a/src/system/runtime_loader/elf_versioning.cpp +++ b/src/system/runtime_loader/elf_versioning.cpp @@ -21,7 +21,7 @@ assert_defined_image_version(image_t* dependentImage, image_t* image, // later when resolving versioned symbols. if (image->version_definitions == NULL) { FATAL("%s: No version information available (required by %s)\n", - image->name, dependentImage->name); + image->path, dependentImage->path); return B_OK; } @@ -42,7 +42,7 @@ assert_defined_image_version(image_t* dependentImage, image_t* image, // version not found -- fail, if not weak if (!weak) { - FATAL("%s: version \"%s\" not found (required by %s)\n", image->name, + FATAL("%s: version \"%s\" not found (required by %s)\n", image->path, neededVersion.name, dependentImage->name); return B_MISSING_SYMBOL; } @@ -66,8 +66,8 @@ init_image_version_infos(image_t* image) Elf32_Verdef* definition = image->version_definitions; for (uint32 i = 0; i < image->num_version_definitions; i++) { if (definition->vd_version != 1) { - FATAL("Unsupported version definition revision: %u\n", - definition->vd_version); + FATAL("%s: Unsupported version definition revision: %u\n", + image->path, definition->vd_version); return B_BAD_VALUE; } @@ -84,8 +84,8 @@ init_image_version_infos(image_t* image) Elf32_Verneed* needed = image->needed_versions; for (uint32 i = 0; i < image->num_needed_versions; i++) { if (needed->vn_version != 1) { - FATAL("Unsupported version needed revision: %u\n", - needed->vn_version); + FATAL("%s: Unsupported version needed revision: %u\n", + image->path, needed->vn_version); return B_BAD_VALUE; } @@ -177,7 +177,8 @@ check_needed_image_versions(image_t* image) if (dependency == NULL) { // This can't really happen, unless the object file is broken, since // the file should also appear in DT_NEEDED. - FATAL("Version dependency \"%s\" not found", fileName); + FATAL("%s: Version dependency \"%s\" not found", image->path, + fileName); return B_FILE_NOT_FOUND; }