From owner-svn-src-all@freebsd.org Sat Nov 2 19:48:43 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7881B161B85; Sat, 2 Nov 2019 19:48:43 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4758kg2ZcJz46PK; Sat, 2 Nov 2019 19:48:43 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 367CC4D3; Sat, 2 Nov 2019 19:48:43 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xA2JmhKw050228; Sat, 2 Nov 2019 19:48:43 GMT (envelope-from mhorne@FreeBSD.org) Received: (from mhorne@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xA2JmhxF050227; Sat, 2 Nov 2019 19:48:43 GMT (envelope-from mhorne@FreeBSD.org) Message-Id: <201911021948.xA2JmhxF050227@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mhorne set sender to mhorne@FreeBSD.org using -f From: Mitchell Horne Date: Sat, 2 Nov 2019 19:48:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r354261 - stable/12/sys/riscv/riscv X-SVN-Group: stable-12 X-SVN-Commit-Author: mhorne X-SVN-Commit-Paths: stable/12/sys/riscv/riscv X-SVN-Commit-Revision: 354261 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Nov 2019 19:48:43 -0000 Author: mhorne Date: Sat Nov 2 19:48:42 2019 New Revision: 354261 URL: https://svnweb.freebsd.org/changeset/base/354261 Log: MFC r352729: Cleanup of elf_machdep.c Fix some style(9) violations. This also changes the name of the machine-dependent sysctl kern.debug_kld to debug.kld_reloc, and changes its type from int to bool. This is acceptable since we are not currently concerned with preserving the RISC-V ABI. Reviewed by: markj, kp Differential Revision: https://reviews.freebsd.org/D21772 Modified: stable/12/sys/riscv/riscv/elf_machdep.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/riscv/riscv/elf_machdep.c ============================================================================== --- stable/12/sys/riscv/riscv/elf_machdep.c Sat Nov 2 19:46:39 2019 (r354260) +++ stable/12/sys/riscv/riscv/elf_machdep.c Sat Nov 2 19:48:42 2019 (r354261) @@ -110,13 +110,11 @@ static Elf64_Brandinfo freebsd_brand_info = { }; SYSINIT(elf64, SI_SUB_EXEC, SI_ORDER_FIRST, - (sysinit_cfunc_t) elf64_insert_brand_entry, - &freebsd_brand_info); + (sysinit_cfunc_t)elf64_insert_brand_entry, &freebsd_brand_info); -static int debug_kld; -SYSCTL_INT(_kern, OID_AUTO, debug_kld, - CTLFLAG_RW, &debug_kld, 0, - "Activate debug prints in elf_reloc_internal()"); +static bool debug_kld; +SYSCTL_BOOL(_debug, OID_AUTO, kld_reloc, CTLFLAG_RW, &debug_kld, 0, + "Activate debug prints in elf_reloc_internal()"); struct type2str_ent { int type; @@ -275,7 +273,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas uint32_t before32_1; uint32_t before32; uint64_t before64; - uint32_t* insn32p; + uint32_t *insn32p; uint32_t imm20; int error; @@ -283,15 +281,15 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas case ELF_RELOC_RELA: rela = (const Elf_Rela *)data; where = (Elf_Addr *)(relocbase + rela->r_offset); - insn32p = (uint32_t*)where; + insn32p = (uint32_t *)where; addend = rela->r_addend; rtype = ELF_R_TYPE(rela->r_info); symidx = ELF_R_SYM(rela->r_info); break; default: printf("%s:%d unknown reloc type %d\n", - __FUNCTION__, __LINE__, type); - return -1; + __FUNCTION__, __LINE__, type); + return (-1); } switch (rtype) { @@ -302,43 +300,36 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas case R_RISCV_JUMP_SLOT: error = lookup(lf, symidx, 1, &addr); if (error != 0) - return -1; + return (-1); val = addr; before64 = *where; if (*where != val) *where = val; - if (debug_kld) - printf("%p %c %-24s %016lx -> %016lx\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before64, *where); + printf("%p %c %-24s %016lx -> %016lx\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before64, *where); break; case R_RISCV_RELATIVE: before64 = *where; - *where = elf_relocaddr(lf, relocbase + addend); - if (debug_kld) - printf("%p %c %-24s %016lx -> %016lx\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before64, *where); + printf("%p %c %-24s %016lx -> %016lx\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before64, *where); break; case R_RISCV_JAL: error = lookup(lf, symidx, 1, &addr); if (error != 0) - return -1; + return (-1); val = addr - (Elf_Addr)where; - if ((val <= -(1UL << 20) || (1UL << 20) <= val)) { + if (val <= -(1UL << 20) || (1UL << 20) <= val) { printf("kldload: huge offset against R_RISCV_JAL\n"); - return -1; + return (-1); } before32 = *insn32p; @@ -346,13 +337,10 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas *insn32p = insert_imm(*insn32p, val, 10, 1, 21); *insn32p = insert_imm(*insn32p, val, 11, 11, 20); *insn32p = insert_imm(*insn32p, val, 19, 12, 12); - if (debug_kld) - printf("%p %c %-24s %08x -> %08x\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before32, *insn32p); + printf("%p %c %-24s %08x -> %08x\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before32, *insn32p); break; case R_RISCV_CALL: @@ -360,14 +348,15 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas * R_RISCV_CALL relocates 8-byte region that consists * of the sequence of AUIPC and JALR. */ - /* calculate and check the pc relative offset. */ + /* Calculate and check the pc relative offset. */ error = lookup(lf, symidx, 1, &addr); if (error != 0) - return -1; + return (-1); + val = addr - (Elf_Addr)where; - if ((val <= -(1UL << 32) || (1UL << 32) <= val)) { + if (val <= -(1UL << 32) || (1UL << 32) <= val) { printf("kldload: huge offset against R_RISCV_CALL\n"); - return -1; + return (-1); } /* Relocate AUIPC. */ @@ -378,112 +367,91 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas /* Relocate JALR. */ before32_1 = insn32p[1]; insn32p[1] = insert_imm(insn32p[1], val, 11, 0, 20); - if (debug_kld) - printf("%p %c %-24s %08x %08x -> %08x %08x\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before32, insn32p[0], - before32_1, insn32p[1]); + printf("%p %c %-24s %08x %08x -> %08x %08x\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before32, insn32p[0], before32_1, insn32p[1]); break; case R_RISCV_PCREL_HI20: val = addr - (Elf_Addr)where; - insn32p = (uint32_t*)where; + insn32p = (uint32_t *)where; before32 = *insn32p; imm20 = calc_hi20_imm(val); *insn32p = insert_imm(*insn32p, imm20, 31, 12, 12); - if (debug_kld) - printf("%p %c %-24s %08x -> %08x\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before32, *insn32p); + printf("%p %c %-24s %08x -> %08x\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before32, *insn32p); break; case R_RISCV_PCREL_LO12_I: val = addr - (Elf_Addr)where; - insn32p = (uint32_t*)where; + insn32p = (uint32_t *)where; before32 = *insn32p; *insn32p = insert_imm(*insn32p, addr, 11, 0, 20); - if (debug_kld) - printf("%p %c %-24s %08x -> %08x\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before32, *insn32p); + printf("%p %c %-24s %08x -> %08x\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before32, *insn32p); break; case R_RISCV_PCREL_LO12_S: val = addr - (Elf_Addr)where; - insn32p = (uint32_t*)where; + insn32p = (uint32_t *)where; before32 = *insn32p; *insn32p = insert_imm(*insn32p, addr, 11, 5, 25); *insn32p = insert_imm(*insn32p, addr, 4, 0, 7); if (debug_kld) - printf("%p %c %-24s %08x -> %08x\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before32, *insn32p); + printf("%p %c %-24s %08x -> %08x\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before32, *insn32p); break; case R_RISCV_HI20: error = lookup(lf, symidx, 1, &addr); if (error != 0) - return -1; + return (-1); - insn32p = (uint32_t*)where; + insn32p = (uint32_t *)where; before32 = *insn32p; imm20 = calc_hi20_imm(val); *insn32p = insert_imm(*insn32p, imm20, 31, 12, 12); - if (debug_kld) - printf("%p %c %-24s %08x -> %08x\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before32, *insn32p); + printf("%p %c %-24s %08x -> %08x\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before32, *insn32p); break; case R_RISCV_LO12_I: error = lookup(lf, symidx, 1, &addr); if (error != 0) - return -1; + return (-1); val = addr; - insn32p = (uint32_t*)where; + insn32p = (uint32_t *)where; before32 = *insn32p; *insn32p = insert_imm(*insn32p, addr, 11, 0, 20); - if (debug_kld) - printf("%p %c %-24s %08x -> %08x\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before32, *insn32p); + printf("%p %c %-24s %08x -> %08x\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before32, *insn32p); break; case R_RISCV_LO12_S: error = lookup(lf, symidx, 1, &addr); if (error != 0) - return -1; + return (-1); val = addr; - insn32p = (uint32_t*)where; + insn32p = (uint32_t *)where; before32 = *insn32p; *insn32p = insert_imm(*insn32p, addr, 11, 5, 25); *insn32p = insert_imm(*insn32p, addr, 4, 0, 7); - if (debug_kld) - printf("%p %c %-24s %08x -> %08x\n", - where, - (local? 'l': 'g'), - reloctype_to_str(rtype), - before32, *insn32p); + printf("%p %c %-24s %08x -> %08x\n", where, + (local ? 'l' : 'g'), reloctype_to_str(rtype), + before32, *insn32p); break; default: