Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

objtool: Change "warning:" to "error: " for fatal errors

This is similar to GCC's behavior and makes it more obvious why the
build failed.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/0ea76f4b0e7a370711ed9f75fd0792bb5979c2bf.1743481539.git.jpoimboe@kernel.org

authored by

Josh Poimboeuf and committed by
Ingo Molnar
3e7be635 0b101771

+226 -222
+9 -5
tools/objtool/arch/loongarch/decode.c
··· 63 63 if (elf->ehdr.e_machine == EM_LOONGARCH) 64 64 return true; 65 65 66 - WARN("unexpected ELF machine type %d", elf->ehdr.e_machine); 66 + ERROR("unexpected ELF machine type %d", elf->ehdr.e_machine); 67 67 return false; 68 68 } 69 69 ··· 327 327 { 328 328 static u32 nop; 329 329 330 - if (len != LOONGARCH_INSN_SIZE) 331 - WARN("invalid NOP size: %d\n", len); 330 + if (len != LOONGARCH_INSN_SIZE) { 331 + ERROR("invalid NOP size: %d\n", len); 332 + return NULL; 333 + } 332 334 333 335 nop = LOONGARCH_INSN_NOP; 334 336 ··· 341 339 { 342 340 static u32 ret; 343 341 344 - if (len != LOONGARCH_INSN_SIZE) 345 - WARN("invalid RET size: %d\n", len); 342 + if (len != LOONGARCH_INSN_SIZE) { 343 + ERROR("invalid RET size: %d\n", len); 344 + return NULL; 345 + } 346 346 347 347 emit_jirl((union loongarch_instruction *)&ret, LOONGARCH_GPR_RA, LOONGARCH_GPR_ZERO, 0); 348 348
+4 -4
tools/objtool/arch/loongarch/orc.c
··· 41 41 orc->type = ORC_TYPE_REGS_PARTIAL; 42 42 break; 43 43 default: 44 - WARN_INSN(insn, "unknown unwind hint type %d", cfi->type); 44 + ERROR_INSN(insn, "unknown unwind hint type %d", cfi->type); 45 45 return -1; 46 46 } 47 47 ··· 55 55 orc->sp_reg = ORC_REG_FP; 56 56 break; 57 57 default: 58 - WARN_INSN(insn, "unknown CFA base reg %d", cfi->cfa.base); 58 + ERROR_INSN(insn, "unknown CFA base reg %d", cfi->cfa.base); 59 59 return -1; 60 60 } 61 61 ··· 72 72 orc->fp_reg = ORC_REG_FP; 73 73 break; 74 74 default: 75 - WARN_INSN(insn, "unknown FP base reg %d", fp->base); 75 + ERROR_INSN(insn, "unknown FP base reg %d", fp->base); 76 76 return -1; 77 77 } 78 78 ··· 89 89 orc->ra_reg = ORC_REG_FP; 90 90 break; 91 91 default: 92 - WARN_INSN(insn, "unknown RA base reg %d", ra->base); 92 + ERROR_INSN(insn, "unknown RA base reg %d", ra->base); 93 93 return -1; 94 94 } 95 95
+7 -8
tools/objtool/arch/x86/decode.c
··· 36 36 case EM_386: 37 37 return 0; 38 38 default: 39 - WARN("unexpected ELF machine type %d", elf->ehdr.e_machine); 39 + ERROR("unexpected ELF machine type %d", elf->ehdr.e_machine); 40 40 return -1; 41 41 } 42 42 } ··· 173 173 ret = insn_decode(&ins, sec->data->d_buf + offset, maxlen, 174 174 x86_64 ? INSN_MODE_64 : INSN_MODE_32); 175 175 if (ret < 0) { 176 - WARN("can't decode instruction at %s:0x%lx", sec->name, offset); 176 + ERROR("can't decode instruction at %s:0x%lx", sec->name, offset); 177 177 return -1; 178 178 } 179 179 ··· 321 321 break; 322 322 323 323 default: 324 - /* WARN ? */ 324 + /* ERROR ? */ 325 325 break; 326 326 } 327 327 ··· 561 561 if (ins.prefixes.nbytes == 1 && 562 562 ins.prefixes.bytes[0] == 0xf2) { 563 563 /* ENQCMD cannot be used in the kernel. */ 564 - WARN("ENQCMD instruction at %s:%lx", sec->name, 565 - offset); 564 + WARN("ENQCMD instruction at %s:%lx", sec->name, offset); 566 565 } 567 566 568 567 } else if (op2 == 0xa0 || op2 == 0xa8) { ··· 645 646 if (disp->sym->type == STT_SECTION) 646 647 func = find_symbol_by_offset(disp->sym->sec, reloc_addend(disp)); 647 648 if (!func) { 648 - WARN("no func for pv_ops[]"); 649 + ERROR("no func for pv_ops[]"); 649 650 return -1; 650 651 } 651 652 ··· 775 776 }; 776 777 777 778 if (len < 1 || len > 5) { 778 - WARN("invalid NOP size: %d\n", len); 779 + ERROR("invalid NOP size: %d\n", len); 779 780 return NULL; 780 781 } 781 782 ··· 795 796 }; 796 797 797 798 if (len < 1 || len > 5) { 798 - WARN("invalid RET size: %d\n", len); 799 + ERROR("invalid RET size: %d\n", len); 799 800 return NULL; 800 801 } 801 802
+3 -3
tools/objtool/arch/x86/orc.c
··· 40 40 orc->type = ORC_TYPE_REGS_PARTIAL; 41 41 break; 42 42 default: 43 - WARN_INSN(insn, "unknown unwind hint type %d", cfi->type); 43 + ERROR_INSN(insn, "unknown unwind hint type %d", cfi->type); 44 44 return -1; 45 45 } 46 46 ··· 72 72 orc->sp_reg = ORC_REG_DX; 73 73 break; 74 74 default: 75 - WARN_INSN(insn, "unknown CFA base reg %d", cfi->cfa.base); 75 + ERROR_INSN(insn, "unknown CFA base reg %d", cfi->cfa.base); 76 76 return -1; 77 77 } 78 78 ··· 87 87 orc->bp_reg = ORC_REG_BP; 88 88 break; 89 89 default: 90 - WARN_INSN(insn, "unknown BP base reg %d", bp->base); 90 + ERROR_INSN(insn, "unknown BP base reg %d", bp->base); 91 91 return -1; 92 92 } 93 93
+15 -15
tools/objtool/builtin-check.c
··· 139 139 static bool opts_valid(void) 140 140 { 141 141 if (opts.mnop && !opts.mcount) { 142 - WARN("--mnop requires --mcount"); 142 + ERROR("--mnop requires --mcount"); 143 143 return false; 144 144 } 145 145 146 146 if (opts.noinstr && !opts.link) { 147 - WARN("--noinstr requires --link"); 147 + ERROR("--noinstr requires --link"); 148 148 return false; 149 149 } 150 150 151 151 if (opts.ibt && !opts.link) { 152 - WARN("--ibt requires --link"); 152 + ERROR("--ibt requires --link"); 153 153 return false; 154 154 } 155 155 156 156 if (opts.unret && !opts.link) { 157 - WARN("--unret requires --link"); 157 + ERROR("--unret requires --link"); 158 158 return false; 159 159 } 160 160 ··· 171 171 opts.static_call || 172 172 opts.uaccess) { 173 173 if (opts.dump_orc) { 174 - WARN("--dump can't be combined with other actions"); 174 + ERROR("--dump can't be combined with other actions"); 175 175 return false; 176 176 } 177 177 ··· 181 181 if (opts.dump_orc) 182 182 return true; 183 183 184 - WARN("At least one action required"); 184 + ERROR("At least one action required"); 185 185 return false; 186 186 } 187 187 ··· 194 194 195 195 src_fd = open(src, O_RDONLY); 196 196 if (src_fd == -1) { 197 - WARN("can't open %s for reading: %s", src, strerror(errno)); 197 + ERROR("can't open %s for reading: %s", src, strerror(errno)); 198 198 return 1; 199 199 } 200 200 201 201 dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0400); 202 202 if (dst_fd == -1) { 203 - WARN("can't open %s for writing: %s", dst, strerror(errno)); 203 + ERROR("can't open %s for writing: %s", dst, strerror(errno)); 204 204 return 1; 205 205 } 206 206 207 207 if (fstat(src_fd, &stat) == -1) { 208 - WARN_GLIBC("fstat"); 208 + ERROR_GLIBC("fstat"); 209 209 return 1; 210 210 } 211 211 212 212 if (fchmod(dst_fd, stat.st_mode) == -1) { 213 - WARN_GLIBC("fchmod"); 213 + ERROR_GLIBC("fchmod"); 214 214 return 1; 215 215 } 216 216 217 217 for (to_copy = stat.st_size; to_copy > 0; to_copy -= copied) { 218 218 copied = sendfile(dst_fd, src_fd, &offset, to_copy); 219 219 if (copied == -1) { 220 - WARN_GLIBC("sendfile"); 220 + ERROR_GLIBC("sendfile"); 221 221 return 1; 222 222 } 223 223 } ··· 231 231 { 232 232 orig_argv = calloc(argc, sizeof(char *)); 233 233 if (!orig_argv) { 234 - WARN_GLIBC("calloc"); 234 + ERROR_GLIBC("calloc"); 235 235 exit(1); 236 236 } 237 237 238 238 for (int i = 0; i < argc; i++) { 239 239 orig_argv[i] = strdup(argv[i]); 240 240 if (!orig_argv[i]) { 241 - WARN_GLIBC("strdup(%s)", argv[i]); 241 + ERROR_GLIBC("strdup(%s)", argv[i]); 242 242 exit(1); 243 243 } 244 244 }; ··· 257 257 */ 258 258 backup = malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1); 259 259 if (!backup) { 260 - WARN_GLIBC("malloc"); 260 + ERROR_GLIBC("malloc"); 261 261 goto print; 262 262 } 263 263 ··· 319 319 return 1; 320 320 321 321 if (!opts.link && has_multiple_files(file->elf)) { 322 - WARN("Linked object requires --link"); 322 + ERROR("Linked object requires --link"); 323 323 return 1; 324 324 } 325 325
+60 -67
tools/objtool/check.c
··· 348 348 { 349 349 struct cfi_state *cfi = calloc(1, sizeof(struct cfi_state)); 350 350 if (!cfi) { 351 - WARN_GLIBC("calloc"); 351 + ERROR_GLIBC("calloc"); 352 352 exit(1); 353 353 } 354 354 nr_cfi++; ··· 404 404 PROT_READ|PROT_WRITE, 405 405 MAP_PRIVATE|MAP_ANON, -1, 0); 406 406 if (cfi_hash == (void *)-1L) { 407 - WARN_GLIBC("mmap fail cfi_hash"); 407 + ERROR_GLIBC("mmap fail cfi_hash"); 408 408 cfi_hash = NULL; 409 409 } else if (opts.stats) { 410 410 printf("cfi_bits: %d\n", cfi_bits); ··· 460 460 if (!insns || idx == INSN_CHUNK_MAX) { 461 461 insns = calloc(sizeof(*insn), INSN_CHUNK_SIZE); 462 462 if (!insns) { 463 - WARN_GLIBC("calloc"); 463 + ERROR_GLIBC("calloc"); 464 464 return -1; 465 465 } 466 466 idx = 0; ··· 495 495 nr_insns++; 496 496 } 497 497 498 - // printf("%s: last chunk used: %d\n", sec->name, (int)idx); 499 - 500 498 sec_for_each_sym(sec, func) { 501 499 if (func->type != STT_NOTYPE && func->type != STT_FUNC) 502 500 continue; ··· 503 505 /* Heuristic: likely an "end" symbol */ 504 506 if (func->type == STT_NOTYPE) 505 507 continue; 506 - WARN("%s(): STT_FUNC at end of section", 507 - func->name); 508 + ERROR("%s(): STT_FUNC at end of section", func->name); 508 509 return -1; 509 510 } 510 511 ··· 511 514 continue; 512 515 513 516 if (!find_insn(file, sec, func->offset)) { 514 - WARN("%s(): can't find starting instruction", 515 - func->name); 517 + ERROR("%s(): can't find starting instruction", func->name); 516 518 return -1; 517 519 } 518 520 ··· 565 569 func = find_symbol_by_offset(reloc->sym->sec, 566 570 reloc_addend(reloc)); 567 571 if (!func) { 568 - WARN_FUNC("can't find func at %s[%d]", 569 - reloc->sym->sec, reloc_addend(reloc), 570 - symname, idx); 572 + ERROR_FUNC(reloc->sym->sec, reloc_addend(reloc), 573 + "can't find func at %s[%d]", symname, idx); 571 574 return -1; 572 575 } 573 576 ··· 609 614 nr = sym->len / sizeof(unsigned long); 610 615 file->pv_ops = calloc(sizeof(struct pv_state), nr); 611 616 if (!file->pv_ops) { 612 - WARN_GLIBC("calloc"); 617 + ERROR_GLIBC("calloc"); 613 618 return -1; 614 619 } 615 620 ··· 668 673 /* find key symbol */ 669 674 key_name = strdup(insn_call_dest(insn)->name); 670 675 if (!key_name) { 671 - WARN_GLIBC("strdup"); 676 + ERROR_GLIBC("strdup"); 672 677 return -1; 673 678 } 674 679 if (strncmp(key_name, STATIC_CALL_TRAMP_PREFIX_STR, 675 680 STATIC_CALL_TRAMP_PREFIX_LEN)) { 676 - WARN("static_call: trampoline name malformed: %s", key_name); 681 + ERROR("static_call: trampoline name malformed: %s", key_name); 677 682 return -1; 678 683 } 679 684 tmp = key_name + STATIC_CALL_TRAMP_PREFIX_LEN - STATIC_CALL_KEY_PREFIX_LEN; ··· 682 687 key_sym = find_symbol_by_name(file->elf, tmp); 683 688 if (!key_sym) { 684 689 if (!opts.module) { 685 - WARN("static_call: can't find static_call_key symbol: %s", tmp); 690 + ERROR("static_call: can't find static_call_key symbol: %s", tmp); 686 691 return -1; 687 692 } 688 693 ··· 828 833 insn->offset == sym->offset && 829 834 (!strcmp(sym->name, "init_module") || 830 835 !strcmp(sym->name, "cleanup_module"))) { 831 - WARN("%s(): Magic init_module() function name is deprecated, use module_init(fn) instead", 832 - sym->name); 836 + ERROR("%s(): Magic init_module() function name is deprecated, use module_init(fn) instead", 837 + sym->name); 833 838 return -1; 834 839 } 835 840 ··· 1003 1008 break; 1004 1009 1005 1010 default: 1006 - WARN("unexpected relocation symbol type in %s: %d", 1007 - rsec->name, reloc->sym->type); 1011 + ERROR("unexpected relocation symbol type in %s: %d", 1012 + rsec->name, reloc->sym->type); 1008 1013 return -1; 1009 1014 } 1010 1015 ··· 1554 1559 dest_off == func->offset + func->len) 1555 1560 continue; 1556 1561 1557 - WARN_INSN(insn, "can't find jump dest instruction at %s+0x%lx", 1558 - dest_sec->name, dest_off); 1562 + ERROR_INSN(insn, "can't find jump dest instruction at %s+0x%lx", 1563 + dest_sec->name, dest_off); 1559 1564 return -1; 1560 1565 } 1561 1566 ··· 1661 1666 continue; 1662 1667 1663 1668 if (!insn_call_dest(insn)) { 1664 - WARN_INSN(insn, "unannotated intra-function call"); 1669 + ERROR_INSN(insn, "unannotated intra-function call"); 1665 1670 return -1; 1666 1671 } 1667 1672 1668 1673 if (func && insn_call_dest(insn)->type != STT_FUNC) { 1669 - WARN_INSN(insn, "unsupported call to non-function"); 1674 + ERROR_INSN(insn, "unsupported call to non-function"); 1670 1675 return -1; 1671 1676 } 1672 1677 ··· 1674 1679 dest_off = arch_dest_reloc_offset(reloc_addend(reloc)); 1675 1680 dest = find_call_destination(reloc->sym->sec, dest_off); 1676 1681 if (!dest) { 1677 - WARN_INSN(insn, "can't find call dest symbol at %s+0x%lx", 1678 - reloc->sym->sec->name, dest_off); 1682 + ERROR_INSN(insn, "can't find call dest symbol at %s+0x%lx", 1683 + reloc->sym->sec->name, dest_off); 1679 1684 return -1; 1680 1685 } 1681 1686 ··· 1717 1722 1718 1723 orig_alt_group = calloc(1, sizeof(*orig_alt_group)); 1719 1724 if (!orig_alt_group) { 1720 - WARN_GLIBC("calloc"); 1725 + ERROR_GLIBC("calloc"); 1721 1726 return -1; 1722 1727 } 1723 1728 orig_alt_group->cfi = calloc(special_alt->orig_len, 1724 1729 sizeof(struct cfi_state *)); 1725 1730 if (!orig_alt_group->cfi) { 1726 - WARN_GLIBC("calloc"); 1731 + ERROR_GLIBC("calloc"); 1727 1732 return -1; 1728 1733 } 1729 1734 ··· 1743 1748 } else { 1744 1749 if (orig_alt_group->last_insn->offset + orig_alt_group->last_insn->len - 1745 1750 orig_alt_group->first_insn->offset != special_alt->orig_len) { 1746 - WARN_INSN(orig_insn, "weirdly overlapping alternative! %ld != %d", 1747 - orig_alt_group->last_insn->offset + 1748 - orig_alt_group->last_insn->len - 1749 - orig_alt_group->first_insn->offset, 1750 - special_alt->orig_len); 1751 + ERROR_INSN(orig_insn, "weirdly overlapping alternative! %ld != %d", 1752 + orig_alt_group->last_insn->offset + 1753 + orig_alt_group->last_insn->len - 1754 + orig_alt_group->first_insn->offset, 1755 + special_alt->orig_len); 1751 1756 return -1; 1752 1757 } 1753 1758 } 1754 1759 1755 1760 new_alt_group = calloc(1, sizeof(*new_alt_group)); 1756 1761 if (!new_alt_group) { 1757 - WARN_GLIBC("calloc"); 1762 + ERROR_GLIBC("calloc"); 1758 1763 return -1; 1759 1764 } 1760 1765 ··· 1768 1773 */ 1769 1774 nop = calloc(1, sizeof(*nop)); 1770 1775 if (!nop) { 1771 - WARN_GLIBC("calloc"); 1776 + ERROR_GLIBC("calloc"); 1772 1777 return -1; 1773 1778 } 1774 1779 memset(nop, 0, sizeof(*nop)); ··· 1810 1815 if (alt_reloc && arch_pc_relative_reloc(alt_reloc) && 1811 1816 !arch_support_alt_relocation(special_alt, insn, alt_reloc)) { 1812 1817 1813 - WARN_INSN(insn, "unsupported relocation in alternatives section"); 1818 + ERROR_INSN(insn, "unsupported relocation in alternatives section"); 1814 1819 return -1; 1815 1820 } 1816 1821 ··· 1824 1829 if (dest_off == special_alt->new_off + special_alt->new_len) { 1825 1830 insn->jump_dest = next_insn_same_sec(file, orig_alt_group->last_insn); 1826 1831 if (!insn->jump_dest) { 1827 - WARN_INSN(insn, "can't find alternative jump destination"); 1832 + ERROR_INSN(insn, "can't find alternative jump destination"); 1828 1833 return -1; 1829 1834 } 1830 1835 } 1831 1836 } 1832 1837 1833 1838 if (!last_new_insn) { 1834 - WARN_FUNC("can't find last new alternative instruction", 1835 - special_alt->new_sec, special_alt->new_off); 1839 + ERROR_FUNC(special_alt->new_sec, special_alt->new_off, 1840 + "can't find last new alternative instruction"); 1836 1841 return -1; 1837 1842 } 1838 1843 ··· 1859 1864 if (orig_insn->type != INSN_JUMP_UNCONDITIONAL && 1860 1865 orig_insn->type != INSN_NOP) { 1861 1866 1862 - WARN_INSN(orig_insn, "unsupported instruction at jump label"); 1867 + ERROR_INSN(orig_insn, "unsupported instruction at jump label"); 1863 1868 return -1; 1864 1869 } 1865 1870 ··· 1918 1923 orig_insn = find_insn(file, special_alt->orig_sec, 1919 1924 special_alt->orig_off); 1920 1925 if (!orig_insn) { 1921 - WARN_FUNC("special: can't find orig instruction", 1922 - special_alt->orig_sec, special_alt->orig_off); 1926 + ERROR_FUNC(special_alt->orig_sec, special_alt->orig_off, 1927 + "special: can't find orig instruction"); 1923 1928 return -1; 1924 1929 } 1925 1930 ··· 1928 1933 new_insn = find_insn(file, special_alt->new_sec, 1929 1934 special_alt->new_off); 1930 1935 if (!new_insn) { 1931 - WARN_FUNC("special: can't find new instruction", 1932 - special_alt->new_sec, 1933 - special_alt->new_off); 1936 + ERROR_FUNC(special_alt->new_sec, special_alt->new_off, 1937 + "special: can't find new instruction"); 1934 1938 return -1; 1935 1939 } 1936 1940 } 1937 1941 1938 1942 if (special_alt->group) { 1939 1943 if (!special_alt->orig_len) { 1940 - WARN_INSN(orig_insn, "empty alternative entry"); 1944 + ERROR_INSN(orig_insn, "empty alternative entry"); 1941 1945 continue; 1942 1946 } 1943 1947 ··· 1954 1960 1955 1961 alt = calloc(1, sizeof(*alt)); 1956 1962 if (!alt) { 1957 - WARN_GLIBC("calloc"); 1963 + ERROR_GLIBC("calloc"); 1958 1964 return -1; 1959 1965 } 1960 1966 ··· 2031 2037 2032 2038 alt = calloc(1, sizeof(*alt)); 2033 2039 if (!alt) { 2034 - WARN_GLIBC("calloc"); 2040 + ERROR_GLIBC("calloc"); 2035 2041 return -1; 2036 2042 } 2037 2043 ··· 2043 2049 } 2044 2050 2045 2051 if (!prev_offset) { 2046 - WARN_INSN(insn, "can't find switch jump table"); 2052 + ERROR_INSN(insn, "can't find switch jump table"); 2047 2053 return -1; 2048 2054 } 2049 2055 ··· 2201 2207 return 0; 2202 2208 2203 2209 if (!sec->rsec) { 2204 - WARN("missing .rela.discard.unwind_hints section"); 2210 + ERROR("missing .rela.discard.unwind_hints section"); 2205 2211 return -1; 2206 2212 } 2207 2213 2208 2214 if (sec->sh.sh_size % sizeof(struct unwind_hint)) { 2209 - WARN("struct unwind_hint size mismatch"); 2215 + ERROR("struct unwind_hint size mismatch"); 2210 2216 return -1; 2211 2217 } 2212 2218 ··· 2217 2223 2218 2224 reloc = find_reloc_by_dest(file->elf, sec, i * sizeof(*hint)); 2219 2225 if (!reloc) { 2220 - WARN("can't find reloc for unwind_hints[%d]", i); 2226 + ERROR("can't find reloc for unwind_hints[%d]", i); 2221 2227 return -1; 2222 2228 } 2223 2229 ··· 2226 2232 } else if (reloc->sym->local_label) { 2227 2233 offset = reloc->sym->offset; 2228 2234 } else { 2229 - WARN("unexpected relocation symbol type in %s", sec->rsec->name); 2235 + ERROR("unexpected relocation symbol type in %s", sec->rsec->name); 2230 2236 return -1; 2231 2237 } 2232 2238 2233 2239 insn = find_insn(file, reloc->sym->sec, offset); 2234 2240 if (!insn) { 2235 - WARN("can't find insn for unwind_hints[%d]", i); 2241 + ERROR("can't find insn for unwind_hints[%d]", i); 2236 2242 return -1; 2237 2243 } 2238 2244 ··· 2259 2265 2260 2266 if (sym && sym->bind == STB_GLOBAL) { 2261 2267 if (opts.ibt && insn->type != INSN_ENDBR && !insn->noendbr) { 2262 - WARN_INSN(insn, "UNWIND_HINT_IRET_REGS without ENDBR"); 2268 + ERROR_INSN(insn, "UNWIND_HINT_IRET_REGS without ENDBR"); 2263 2269 return -1; 2264 2270 } 2265 2271 } ··· 2274 2280 cfi = *(insn->cfi); 2275 2281 2276 2282 if (arch_decode_hint_reg(hint->sp_reg, &cfi.cfa.base)) { 2277 - WARN_INSN(insn, "unsupported unwind_hint sp base reg %d", hint->sp_reg); 2283 + ERROR_INSN(insn, "unsupported unwind_hint sp base reg %d", hint->sp_reg); 2278 2284 return -1; 2279 2285 } 2280 2286 ··· 2320 2326 insn = find_insn(file, reloc->sym->sec, offset); 2321 2327 2322 2328 if (!insn) { 2323 - WARN("bad .discard.annotate_insn entry: %d of type %d", reloc_idx(reloc), type); 2329 + ERROR("bad .discard.annotate_insn entry: %d of type %d", reloc_idx(reloc), type); 2324 2330 return -1; 2325 2331 } 2326 2332 ··· 2363 2369 return 0; 2364 2370 2365 2371 if (insn->type != INSN_CALL) { 2366 - WARN_INSN(insn, "intra_function_call not a direct call"); 2372 + ERROR_INSN(insn, "intra_function_call not a direct call"); 2367 2373 return -1; 2368 2374 } 2369 2375 ··· 2377 2383 dest_off = arch_jump_destination(insn); 2378 2384 insn->jump_dest = find_insn(file, insn->sec, dest_off); 2379 2385 if (!insn->jump_dest) { 2380 - WARN_INSN(insn, "can't find call dest at %s+0x%lx", 2381 - insn->sec->name, dest_off); 2386 + ERROR_INSN(insn, "can't find call dest at %s+0x%lx", 2387 + insn->sec->name, dest_off); 2382 2388 return -1; 2383 2389 } 2384 2390 ··· 2397 2403 insn->type != INSN_CALL_DYNAMIC && 2398 2404 insn->type != INSN_RETURN && 2399 2405 insn->type != INSN_NOP) { 2400 - WARN_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop"); 2406 + ERROR_INSN(insn, "retpoline_safe hint not an indirect jump/call/ret/nop"); 2401 2407 return -1; 2402 2408 } 2403 2409 ··· 2429 2435 break; 2430 2436 2431 2437 default: 2432 - WARN_INSN(insn, "Unknown annotation type: %d", type); 2438 + ERROR_INSN(insn, "Unknown annotation type: %d", type); 2433 2439 return -1; 2434 2440 } 2435 2441 ··· 4387 4393 if (dest->noendbr) 4388 4394 return 0; 4389 4395 4390 - WARN_FUNC("data relocation to !ENDBR: %s", 4391 - reloc->sec->base, reloc_offset(reloc), 4392 - offstr(dest->sec, dest->offset)); 4396 + WARN_FUNC(reloc->sec->base, reloc_offset(reloc), 4397 + "data relocation to !ENDBR: %s", offstr(dest->sec, dest->offset)); 4393 4398 4394 4399 return 1; 4395 4400 } ··· 4573 4580 if (!funcs) { 4574 4581 funcs = malloc(strlen(sym->name) + 1); 4575 4582 if (!funcs) { 4576 - WARN_GLIBC("malloc"); 4583 + ERROR_GLIBC("malloc"); 4577 4584 return; 4578 4585 } 4579 4586 strcpy(funcs, sym->name); 4580 4587 } else { 4581 4588 tmp = malloc(strlen(funcs) + strlen(sym->name) + 2); 4582 4589 if (!tmp) { 4583 - WARN_GLIBC("malloc"); 4590 + ERROR_GLIBC("malloc"); 4584 4591 return; 4585 4592 } 4586 4593 sprintf(tmp, "%s %s", funcs, sym->name);
+71 -79
tools/objtool/elf.c
··· 72 72 obj; \ 73 73 obj = elf_list_entry(obj->member.next, typeof(*(obj)), member)) 74 74 75 - #define elf_alloc_hash(name, size) \ 76 - ({ \ 77 - __elf_bits(name) = max(10, ilog2(size)); \ 75 + #define elf_alloc_hash(name, size) \ 76 + ({ \ 77 + __elf_bits(name) = max(10, ilog2(size)); \ 78 78 __elf_table(name) = mmap(NULL, sizeof(struct elf_hash_node *) << __elf_bits(name), \ 79 - PROT_READ|PROT_WRITE, \ 80 - MAP_PRIVATE|MAP_ANON, -1, 0); \ 81 - if (__elf_table(name) == (void *)-1L) { \ 82 - WARN("mmap fail " #name); \ 83 - __elf_table(name) = NULL; \ 84 - } \ 85 - __elf_table(name); \ 79 + PROT_READ|PROT_WRITE, \ 80 + MAP_PRIVATE|MAP_ANON, -1, 0); \ 81 + if (__elf_table(name) == (void *)-1L) { \ 82 + ERROR_GLIBC("mmap fail " #name); \ 83 + __elf_table(name) = NULL; \ 84 + } \ 85 + __elf_table(name); \ 86 86 }) 87 87 88 88 static inline unsigned long __sym_start(struct symbol *s) ··· 316 316 int i; 317 317 318 318 if (elf_getshdrnum(elf->elf, &sections_nr)) { 319 - WARN_ELF("elf_getshdrnum"); 319 + ERROR_ELF("elf_getshdrnum"); 320 320 return -1; 321 321 } 322 322 323 323 if (elf_getshdrstrndx(elf->elf, &shstrndx)) { 324 - WARN_ELF("elf_getshdrstrndx"); 324 + ERROR_ELF("elf_getshdrstrndx"); 325 325 return -1; 326 326 } 327 327 ··· 331 331 332 332 elf->section_data = calloc(sections_nr, sizeof(*sec)); 333 333 if (!elf->section_data) { 334 - WARN_GLIBC("calloc"); 334 + ERROR_GLIBC("calloc"); 335 335 return -1; 336 336 } 337 337 for (i = 0; i < sections_nr; i++) { ··· 341 341 342 342 s = elf_getscn(elf->elf, i); 343 343 if (!s) { 344 - WARN_ELF("elf_getscn"); 344 + ERROR_ELF("elf_getscn"); 345 345 return -1; 346 346 } 347 347 348 348 sec->idx = elf_ndxscn(s); 349 349 350 350 if (!gelf_getshdr(s, &sec->sh)) { 351 - WARN_ELF("gelf_getshdr"); 351 + ERROR_ELF("gelf_getshdr"); 352 352 return -1; 353 353 } 354 354 355 355 sec->name = elf_strptr(elf->elf, shstrndx, sec->sh.sh_name); 356 356 if (!sec->name) { 357 - WARN_ELF("elf_strptr"); 357 + ERROR_ELF("elf_strptr"); 358 358 return -1; 359 359 } 360 360 361 361 if (sec->sh.sh_size != 0 && !is_dwarf_section(sec)) { 362 362 sec->data = elf_getdata(s, NULL); 363 363 if (!sec->data) { 364 - WARN_ELF("elf_getdata"); 364 + ERROR_ELF("elf_getdata"); 365 365 return -1; 366 366 } 367 367 if (sec->data->d_off != 0 || 368 368 sec->data->d_size != sec->sh.sh_size) { 369 - WARN("unexpected data attributes for %s", 370 - sec->name); 369 + ERROR("unexpected data attributes for %s", sec->name); 371 370 return -1; 372 371 } 373 372 } ··· 386 387 387 388 /* sanity check, one more call to elf_nextscn() should return NULL */ 388 389 if (elf_nextscn(elf->elf, s)) { 389 - WARN("section entry mismatch"); 390 + ERROR("section entry mismatch"); 390 391 return -1; 391 392 } 392 393 ··· 466 467 467 468 elf->symbol_data = calloc(symbols_nr, sizeof(*sym)); 468 469 if (!elf->symbol_data) { 469 - WARN_GLIBC("calloc"); 470 + ERROR_GLIBC("calloc"); 470 471 return -1; 471 472 } 472 473 for (i = 0; i < symbols_nr; i++) { ··· 476 477 477 478 if (!gelf_getsymshndx(symtab->data, shndx_data, i, &sym->sym, 478 479 &shndx)) { 479 - WARN_ELF("gelf_getsymshndx"); 480 + ERROR_ELF("gelf_getsymshndx"); 480 481 goto err; 481 482 } 482 483 483 484 sym->name = elf_strptr(elf->elf, symtab->sh.sh_link, 484 485 sym->sym.st_name); 485 486 if (!sym->name) { 486 - WARN_ELF("elf_strptr"); 487 + ERROR_ELF("elf_strptr"); 487 488 goto err; 488 489 } 489 490 ··· 495 496 496 497 sym->sec = find_section_by_index(elf, shndx); 497 498 if (!sym->sec) { 498 - WARN("couldn't find section for symbol %s", 499 - sym->name); 499 + ERROR("couldn't find section for symbol %s", sym->name); 500 500 goto err; 501 501 } 502 502 if (GELF_ST_TYPE(sym->sym.st_info) == STT_SECTION) { ··· 534 536 pnamelen = coldstr - sym->name; 535 537 pname = strndup(sym->name, pnamelen); 536 538 if (!pname) { 537 - WARN("%s(): failed to allocate memory", 538 - sym->name); 539 + ERROR("%s(): failed to allocate memory", sym->name); 539 540 return -1; 540 541 } 541 542 ··· 542 545 free(pname); 543 546 544 547 if (!pfunc) { 545 - WARN("%s(): can't find parent function", 546 - sym->name); 548 + ERROR("%s(): can't find parent function", sym->name); 547 549 return -1; 548 550 } 549 551 ··· 609 613 610 614 s = elf_getscn(elf->elf, symtab->idx); 611 615 if (!s) { 612 - WARN_ELF("elf_getscn"); 616 + ERROR_ELF("elf_getscn"); 613 617 return -1; 614 618 } 615 619 616 620 if (symtab_shndx) { 617 621 t = elf_getscn(elf->elf, symtab_shndx->idx); 618 622 if (!t) { 619 - WARN_ELF("elf_getscn"); 623 + ERROR_ELF("elf_getscn"); 620 624 return -1; 621 625 } 622 626 } ··· 639 643 640 644 if (idx) { 641 645 /* we don't do holes in symbol tables */ 642 - WARN("index out of range"); 646 + ERROR("index out of range"); 643 647 return -1; 644 648 } 645 649 ··· 650 654 651 655 buf = calloc(num, entsize); 652 656 if (!buf) { 653 - WARN("malloc"); 657 + ERROR_GLIBC("calloc"); 654 658 return -1; 655 659 } 656 660 ··· 665 669 if (t) { 666 670 buf = calloc(num, sizeof(Elf32_Word)); 667 671 if (!buf) { 668 - WARN("malloc"); 672 + ERROR_GLIBC("calloc"); 669 673 return -1; 670 674 } 671 675 ··· 683 687 684 688 /* empty blocks should not happen */ 685 689 if (!symtab_data->d_size) { 686 - WARN("zero size data"); 690 + ERROR("zero size data"); 687 691 return -1; 688 692 } 689 693 ··· 698 702 699 703 /* something went side-ways */ 700 704 if (idx < 0) { 701 - WARN("negative index"); 705 + ERROR("negative index"); 702 706 return -1; 703 707 } 704 708 ··· 710 714 } else { 711 715 sym->sym.st_shndx = SHN_XINDEX; 712 716 if (!shndx_data) { 713 - WARN("no .symtab_shndx"); 717 + ERROR("no .symtab_shndx"); 714 718 return -1; 715 719 } 716 720 } 717 721 718 722 if (!gelf_update_symshndx(symtab_data, shndx_data, idx, &sym->sym, shndx)) { 719 - WARN_ELF("gelf_update_symshndx"); 723 + ERROR_ELF("gelf_update_symshndx"); 720 724 return -1; 721 725 } 722 726 ··· 734 738 if (symtab) { 735 739 symtab_shndx = find_section_by_name(elf, ".symtab_shndx"); 736 740 } else { 737 - WARN("no .symtab"); 741 + ERROR("no .symtab"); 738 742 return NULL; 739 743 } 740 744 ··· 756 760 old->idx = new_idx; 757 761 758 762 if (elf_update_symbol(elf, symtab, symtab_shndx, old)) { 759 - WARN("elf_update_symbol move"); 763 + ERROR("elf_update_symbol move"); 760 764 return NULL; 761 765 } 762 766 ··· 774 778 non_local: 775 779 sym->idx = new_idx; 776 780 if (elf_update_symbol(elf, symtab, symtab_shndx, sym)) { 777 - WARN("elf_update_symbol"); 781 + ERROR("elf_update_symbol"); 778 782 return NULL; 779 783 } 780 784 ··· 795 799 struct symbol *sym = calloc(1, sizeof(*sym)); 796 800 797 801 if (!sym) { 798 - WARN_GLIBC("malloc"); 802 + ERROR_GLIBC("malloc"); 799 803 return NULL; 800 804 } 801 805 ··· 825 829 char *name = malloc(namelen); 826 830 827 831 if (!sym || !name) { 828 - WARN_GLIBC("malloc"); 832 + ERROR_GLIBC("malloc"); 829 833 return NULL; 830 834 } 831 835 ··· 854 858 struct reloc *reloc, empty = { 0 }; 855 859 856 860 if (reloc_idx >= sec_num_entries(rsec)) { 857 - WARN("%s: bad reloc_idx %u for %s with %d relocs", 858 - __func__, reloc_idx, rsec->name, sec_num_entries(rsec)); 861 + ERROR("%s: bad reloc_idx %u for %s with %d relocs", 862 + __func__, reloc_idx, rsec->name, sec_num_entries(rsec)); 859 863 return NULL; 860 864 } 861 865 862 866 reloc = &rsec->relocs[reloc_idx]; 863 867 864 868 if (memcmp(reloc, &empty, sizeof(empty))) { 865 - WARN("%s: %s: reloc %d already initialized!", 866 - __func__, rsec->name, reloc_idx); 869 + ERROR("%s: %s: reloc %d already initialized!", 870 + __func__, rsec->name, reloc_idx); 867 871 return NULL; 868 872 } 869 873 ··· 892 896 int addend = insn_off; 893 897 894 898 if (!(insn_sec->sh.sh_flags & SHF_EXECINSTR)) { 895 - WARN("bad call to %s() for data symbol %s", 896 - __func__, sym->name); 899 + ERROR("bad call to %s() for data symbol %s", __func__, sym->name); 897 900 return NULL; 898 901 } 899 902 ··· 921 926 s64 addend) 922 927 { 923 928 if (sym->sec && (sec->sh.sh_flags & SHF_EXECINSTR)) { 924 - WARN("bad call to %s() for text symbol %s", 925 - __func__, sym->name); 929 + ERROR("bad call to %s() for text symbol %s", __func__, sym->name); 926 930 return NULL; 927 931 } 928 932 ··· 947 953 948 954 rsec->base = find_section_by_index(elf, rsec->sh.sh_info); 949 955 if (!rsec->base) { 950 - WARN("can't find base section for reloc section %s", 951 - rsec->name); 956 + ERROR("can't find base section for reloc section %s", rsec->name); 952 957 return -1; 953 958 } 954 959 ··· 956 963 nr_reloc = 0; 957 964 rsec->relocs = calloc(sec_num_entries(rsec), sizeof(*reloc)); 958 965 if (!rsec->relocs) { 959 - WARN_GLIBC("calloc"); 966 + ERROR_GLIBC("calloc"); 960 967 return -1; 961 968 } 962 969 for (i = 0; i < sec_num_entries(rsec); i++) { ··· 966 973 symndx = reloc_sym(reloc); 967 974 reloc->sym = sym = find_symbol_by_index(elf, symndx); 968 975 if (!reloc->sym) { 969 - WARN("can't find reloc entry symbol %d for %s", 970 - symndx, rsec->name); 976 + ERROR("can't find reloc entry symbol %d for %s", symndx, rsec->name); 971 977 return -1; 972 978 } 973 979 ··· 997 1005 998 1006 elf = malloc(sizeof(*elf)); 999 1007 if (!elf) { 1000 - WARN_GLIBC("malloc"); 1008 + ERROR_GLIBC("malloc"); 1001 1009 return NULL; 1002 1010 } 1003 1011 memset(elf, 0, sizeof(*elf)); ··· 1020 1028 1021 1029 elf->elf = elf_begin(elf->fd, cmd, NULL); 1022 1030 if (!elf->elf) { 1023 - WARN_ELF("elf_begin"); 1031 + ERROR_ELF("elf_begin"); 1024 1032 goto err; 1025 1033 } 1026 1034 1027 1035 if (!gelf_getehdr(elf->elf, &elf->ehdr)) { 1028 - WARN_ELF("gelf_getehdr"); 1036 + ERROR_ELF("gelf_getehdr"); 1029 1037 goto err; 1030 1038 } 1031 1039 ··· 1054 1062 if (!strtab) 1055 1063 strtab = find_section_by_name(elf, ".strtab"); 1056 1064 if (!strtab) { 1057 - WARN("can't find .strtab section"); 1065 + ERROR("can't find .strtab section"); 1058 1066 return -1; 1059 1067 } 1060 1068 1061 1069 s = elf_getscn(elf->elf, strtab->idx); 1062 1070 if (!s) { 1063 - WARN_ELF("elf_getscn"); 1071 + ERROR_ELF("elf_getscn"); 1064 1072 return -1; 1065 1073 } 1066 1074 1067 1075 data = elf_newdata(s); 1068 1076 if (!data) { 1069 - WARN_ELF("elf_newdata"); 1077 + ERROR_ELF("elf_newdata"); 1070 1078 return -1; 1071 1079 } 1072 1080 ··· 1091 1099 1092 1100 sec = malloc(sizeof(*sec)); 1093 1101 if (!sec) { 1094 - WARN_GLIBC("malloc"); 1102 + ERROR_GLIBC("malloc"); 1095 1103 return NULL; 1096 1104 } 1097 1105 memset(sec, 0, sizeof(*sec)); ··· 1100 1108 1101 1109 s = elf_newscn(elf->elf); 1102 1110 if (!s) { 1103 - WARN_ELF("elf_newscn"); 1111 + ERROR_ELF("elf_newscn"); 1104 1112 return NULL; 1105 1113 } 1106 1114 1107 1115 sec->name = strdup(name); 1108 1116 if (!sec->name) { 1109 - WARN_GLIBC("strdup"); 1117 + ERROR_GLIBC("strdup"); 1110 1118 return NULL; 1111 1119 } 1112 1120 ··· 1114 1122 1115 1123 sec->data = elf_newdata(s); 1116 1124 if (!sec->data) { 1117 - WARN_ELF("elf_newdata"); 1125 + ERROR_ELF("elf_newdata"); 1118 1126 return NULL; 1119 1127 } 1120 1128 ··· 1124 1132 if (size) { 1125 1133 sec->data->d_buf = malloc(size); 1126 1134 if (!sec->data->d_buf) { 1127 - WARN_GLIBC("malloc"); 1135 + ERROR_GLIBC("malloc"); 1128 1136 return NULL; 1129 1137 } 1130 1138 memset(sec->data->d_buf, 0, size); 1131 1139 } 1132 1140 1133 1141 if (!gelf_getshdr(s, &sec->sh)) { 1134 - WARN_ELF("gelf_getshdr"); 1142 + ERROR_ELF("gelf_getshdr"); 1135 1143 return NULL; 1136 1144 } 1137 1145 ··· 1146 1154 if (!shstrtab) 1147 1155 shstrtab = find_section_by_name(elf, ".strtab"); 1148 1156 if (!shstrtab) { 1149 - WARN("can't find .shstrtab or .strtab section"); 1157 + ERROR("can't find .shstrtab or .strtab section"); 1150 1158 return NULL; 1151 1159 } 1152 1160 sec->sh.sh_name = elf_add_string(elf, shstrtab, sec->name); ··· 1171 1179 1172 1180 rsec_name = malloc(strlen(sec->name) + strlen(".rela") + 1); 1173 1181 if (!rsec_name) { 1174 - WARN_GLIBC("malloc"); 1182 + ERROR_GLIBC("malloc"); 1175 1183 return NULL; 1176 1184 } 1177 1185 strcpy(rsec_name, ".rela"); ··· 1191 1199 1192 1200 rsec->relocs = calloc(sec_num_entries(rsec), sizeof(struct reloc)); 1193 1201 if (!rsec->relocs) { 1194 - WARN_GLIBC("calloc"); 1202 + ERROR_GLIBC("calloc"); 1195 1203 return NULL; 1196 1204 } 1197 1205 ··· 1224 1232 Elf_Data *data = sec->data; 1225 1233 1226 1234 if (data->d_type != ELF_T_BYTE || data->d_off) { 1227 - WARN("write to unexpected data for section: %s", sec->name); 1235 + ERROR("write to unexpected data for section: %s", sec->name); 1228 1236 return -1; 1229 1237 } 1230 1238 ··· 1253 1261 1254 1262 s = elf_getscn(elf->elf, sec->idx); 1255 1263 if (!s) { 1256 - WARN_ELF("elf_getscn"); 1264 + ERROR_ELF("elf_getscn"); 1257 1265 return -1; 1258 1266 } 1259 1267 ··· 1263 1271 1264 1272 if (!data) { 1265 1273 if (size) { 1266 - WARN("end of section data but non-zero size left\n"); 1274 + ERROR("end of section data but non-zero size left\n"); 1267 1275 return -1; 1268 1276 } 1269 1277 return 0; ··· 1271 1279 1272 1280 if (truncated) { 1273 1281 /* when we remove symbols */ 1274 - WARN("truncated; but more data\n"); 1282 + ERROR("truncated; but more data\n"); 1275 1283 return -1; 1276 1284 } 1277 1285 1278 1286 if (!data->d_size) { 1279 - WARN("zero size data"); 1287 + ERROR("zero size data"); 1280 1288 return -1; 1281 1289 } 1282 1290 ··· 1302 1310 if (sec_changed(sec)) { 1303 1311 s = elf_getscn(elf->elf, sec->idx); 1304 1312 if (!s) { 1305 - WARN_ELF("elf_getscn"); 1313 + ERROR_ELF("elf_getscn"); 1306 1314 return -1; 1307 1315 } 1308 1316 1309 1317 /* Note this also flags the section dirty */ 1310 1318 if (!gelf_update_shdr(s, &sec->sh)) { 1311 - WARN_ELF("gelf_update_shdr"); 1319 + ERROR_ELF("gelf_update_shdr"); 1312 1320 return -1; 1313 1321 } 1314 1322 ··· 1321 1329 1322 1330 /* Write all changes to the file. */ 1323 1331 if (elf_update(elf->elf, ELF_C_WRITE) < 0) { 1324 - WARN_ELF("elf_update"); 1332 + ERROR_ELF("elf_update"); 1325 1333 return -1; 1326 1334 } 1327 1335
+35 -16
tools/objtool/include/objtool/warn.h
··· 42 42 return str; 43 43 } 44 44 45 - #define WARN(format, ...) \ 46 - fprintf(stderr, \ 47 - "%s%s%s: objtool: " format "\n", \ 48 - objname ?: "", \ 49 - objname ? ": " : "", \ 50 - opts.werror ? "error" : "warning", \ 45 + #define ___WARN(severity, extra, format, ...) \ 46 + fprintf(stderr, \ 47 + "%s%s%s: objtool" extra ": " format "\n", \ 48 + objname ?: "", \ 49 + objname ? ": " : "", \ 50 + severity, \ 51 51 ##__VA_ARGS__) 52 52 53 - #define WARN_FUNC(format, sec, offset, ...) \ 54 - ({ \ 55 - char *_str = offstr(sec, offset); \ 56 - WARN("%s: " format, _str, ##__VA_ARGS__); \ 57 - free(_str); \ 53 + #define __WARN(severity, format, ...) \ 54 + ___WARN(severity, "", format, ##__VA_ARGS__) 55 + 56 + #define __WARN_LINE(severity, format, ...) \ 57 + ___WARN(severity, " [%s:%d]", format, __FILE__, __LINE__, ##__VA_ARGS__) 58 + 59 + #define __WARN_ELF(severity, format, ...) \ 60 + __WARN_LINE(severity, "%s: " format " failed: %s", __func__, ##__VA_ARGS__, elf_errmsg(-1)) 61 + 62 + #define __WARN_GLIBC(severity, format, ...) \ 63 + __WARN_LINE(severity, "%s: " format " failed: %s", __func__, ##__VA_ARGS__, strerror(errno)) 64 + 65 + #define __WARN_FUNC(severity, sec, offset, format, ...) \ 66 + ({ \ 67 + char *_str = offstr(sec, offset); \ 68 + __WARN(severity, "%s: " format, _str, ##__VA_ARGS__); \ 69 + free(_str); \ 58 70 }) 71 + 72 + #define WARN_STR (opts.werror ? "error" : "warning") 73 + 74 + #define WARN(format, ...) __WARN(WARN_STR, format, ##__VA_ARGS__) 75 + #define WARN_FUNC(sec, offset, format, ...) __WARN_FUNC(WARN_STR, sec, offset, format, ##__VA_ARGS__) 59 76 60 77 #define WARN_INSN(insn, format, ...) \ 61 78 ({ \ 62 79 struct instruction *_insn = (insn); \ 63 80 if (!_insn->sym || !_insn->sym->warned) \ 64 - WARN_FUNC(format, _insn->sec, _insn->offset, \ 81 + WARN_FUNC(_insn->sec, _insn->offset, format, \ 65 82 ##__VA_ARGS__); \ 66 83 if (_insn->sym) \ 67 84 _insn->sym->warned = 1; \ ··· 94 77 } \ 95 78 }) 96 79 97 - #define WARN_ELF(format, ...) \ 98 - WARN("%s: " format " failed: %s", __func__, ##__VA_ARGS__, elf_errmsg(-1)) 80 + #define ERROR_STR "error" 99 81 100 - #define WARN_GLIBC(format, ...) \ 101 - WARN("%s: " format " failed: %s", __func__, ##__VA_ARGS__, strerror(errno)) 82 + #define ERROR(format, ...) __WARN(ERROR_STR, format, ##__VA_ARGS__) 83 + #define ERROR_ELF(format, ...) __WARN_ELF(ERROR_STR, format, ##__VA_ARGS__) 84 + #define ERROR_GLIBC(format, ...) __WARN_GLIBC(ERROR_STR, format, ##__VA_ARGS__) 85 + #define ERROR_FUNC(sec, offset, format, ...) __WARN_FUNC(ERROR_STR, sec, offset, format, ##__VA_ARGS__) 86 + #define ERROR_INSN(insn, format, ...) WARN_FUNC(insn->sec, insn->offset, format, ##__VA_ARGS__) 102 87 103 88 #endif /* _WARN_H */
+2 -2
tools/objtool/objtool.c
··· 23 23 struct objtool_file *objtool_open_read(const char *filename) 24 24 { 25 25 if (file.elf) { 26 - WARN("won't handle more than one file at a time"); 26 + ERROR("won't handle more than one file at a time"); 27 27 return NULL; 28 28 } 29 29 ··· 50 50 return 0; 51 51 52 52 if (!f->pv_ops) { 53 - WARN("paravirt confusion"); 53 + ERROR("paravirt confusion"); 54 54 return -1; 55 55 } 56 56
+15 -15
tools/objtool/orc_dump.c
··· 36 36 37 37 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); 38 38 if (!elf) { 39 - WARN_ELF("elf_begin"); 39 + ERROR_ELF("elf_begin"); 40 40 return -1; 41 41 } 42 42 43 43 if (!elf64_getehdr(elf)) { 44 - WARN_ELF("elf64_getehdr"); 44 + ERROR_ELF("elf64_getehdr"); 45 45 return -1; 46 46 } 47 47 memcpy(&dummy_elf.ehdr, elf64_getehdr(elf), sizeof(dummy_elf.ehdr)); 48 48 49 49 if (elf_getshdrnum(elf, &nr_sections)) { 50 - WARN_ELF("elf_getshdrnum"); 50 + ERROR_ELF("elf_getshdrnum"); 51 51 return -1; 52 52 } 53 53 54 54 if (elf_getshdrstrndx(elf, &shstrtab_idx)) { 55 - WARN_ELF("elf_getshdrstrndx"); 55 + ERROR_ELF("elf_getshdrstrndx"); 56 56 return -1; 57 57 } 58 58 59 59 for (i = 0; i < nr_sections; i++) { 60 60 scn = elf_getscn(elf, i); 61 61 if (!scn) { 62 - WARN_ELF("elf_getscn"); 62 + ERROR_ELF("elf_getscn"); 63 63 return -1; 64 64 } 65 65 66 66 if (!gelf_getshdr(scn, &sh)) { 67 - WARN_ELF("gelf_getshdr"); 67 + ERROR_ELF("gelf_getshdr"); 68 68 return -1; 69 69 } 70 70 71 71 name = elf_strptr(elf, shstrtab_idx, sh.sh_name); 72 72 if (!name) { 73 - WARN_ELF("elf_strptr"); 73 + ERROR_ELF("elf_strptr"); 74 74 return -1; 75 75 } 76 76 77 77 data = elf_getdata(scn, NULL); 78 78 if (!data) { 79 - WARN_ELF("elf_getdata"); 79 + ERROR_ELF("elf_getdata"); 80 80 return -1; 81 81 } 82 82 ··· 99 99 return 0; 100 100 101 101 if (orc_size % sizeof(*orc) != 0) { 102 - WARN("bad .orc_unwind section size"); 102 + ERROR("bad .orc_unwind section size"); 103 103 return -1; 104 104 } 105 105 ··· 107 107 for (i = 0; i < nr_entries; i++) { 108 108 if (rela_orc_ip) { 109 109 if (!gelf_getrela(rela_orc_ip, i, &rela)) { 110 - WARN_ELF("gelf_getrela"); 110 + ERROR_ELF("gelf_getrela"); 111 111 return -1; 112 112 } 113 113 114 114 if (!gelf_getsym(symtab, GELF_R_SYM(rela.r_info), &sym)) { 115 - WARN_ELF("gelf_getsym"); 115 + ERROR_ELF("gelf_getsym"); 116 116 return -1; 117 117 } 118 118 119 119 if (GELF_ST_TYPE(sym.st_info) == STT_SECTION) { 120 120 scn = elf_getscn(elf, sym.st_shndx); 121 121 if (!scn) { 122 - WARN_ELF("elf_getscn"); 122 + ERROR_ELF("elf_getscn"); 123 123 return -1; 124 124 } 125 125 126 126 if (!gelf_getshdr(scn, &sh)) { 127 - WARN_ELF("gelf_getshdr"); 127 + ERROR_ELF("gelf_getshdr"); 128 128 return -1; 129 129 } 130 130 131 131 name = elf_strptr(elf, shstrtab_idx, sh.sh_name); 132 132 if (!name) { 133 - WARN_ELF("elf_strptr"); 133 + ERROR_ELF("elf_strptr"); 134 134 return -1; 135 135 } 136 136 } else { 137 137 name = elf_strptr(elf, strtab_idx, sym.st_name); 138 138 if (!name) { 139 - WARN_ELF("elf_strptr"); 139 + ERROR_ELF("elf_strptr"); 140 140 return -1; 141 141 } 142 142 }
+5 -8
tools/objtool/special.c
··· 86 86 87 87 orig_reloc = find_reloc_by_dest(elf, sec, offset + entry->orig); 88 88 if (!orig_reloc) { 89 - WARN_FUNC("can't find orig reloc", sec, offset + entry->orig); 89 + ERROR_FUNC(sec, offset + entry->orig, "can't find orig reloc"); 90 90 return -1; 91 91 } 92 92 ··· 97 97 if (!entry->group || alt->new_len) { 98 98 new_reloc = find_reloc_by_dest(elf, sec, offset + entry->new); 99 99 if (!new_reloc) { 100 - WARN_FUNC("can't find new reloc", 101 - sec, offset + entry->new); 100 + ERROR_FUNC(sec, offset + entry->new, "can't find new reloc"); 102 101 return -1; 103 102 } 104 103 ··· 113 114 114 115 key_reloc = find_reloc_by_dest(elf, sec, offset + entry->key); 115 116 if (!key_reloc) { 116 - WARN_FUNC("can't find key reloc", 117 - sec, offset + entry->key); 117 + ERROR_FUNC(sec, offset + entry->key, "can't find key reloc"); 118 118 return -1; 119 119 } 120 120 alt->key_addend = reloc_addend(key_reloc); ··· 143 145 continue; 144 146 145 147 if (sec->sh.sh_size % entry->size != 0) { 146 - WARN("%s size not a multiple of %d", 147 - sec->name, entry->size); 148 + ERROR("%s size not a multiple of %d", sec->name, entry->size); 148 149 return -1; 149 150 } 150 151 ··· 152 155 for (idx = 0; idx < nr_entries; idx++) { 153 156 alt = malloc(sizeof(*alt)); 154 157 if (!alt) { 155 - WARN("malloc failed"); 158 + ERROR_GLIBC("malloc failed"); 156 159 return -1; 157 160 } 158 161 memset(alt, 0, sizeof(*alt));