< prev index next >

src/jdk.hotspot.agent/linux/native/libsaproc/salibelf.c

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 122,126 **** --- 122,155 ---- quit: if (phbuf) free(phbuf); return baseaddr; } + + struct elf_section *find_section_by_name(char *name, + int fd, + ELF_EHDR *ehdr, + struct elf_section *scn_cache) { + char *strtab; + int cnt; + int strtab_size; + + // Section cache have to already contain data for e_shstrndx section. + // If it's not true - elf file is broken, so just bail out + if (scn_cache[ehdr->e_shstrndx].c_data == NULL) { + return NULL; + } + + strtab = scn_cache[ehdr->e_shstrndx].c_data; + strtab_size = scn_cache[ehdr->e_shstrndx].c_shdr->sh_size; + + for (cnt = 0; cnt < ehdr->e_shnum; ++cnt) { + if (scn_cache[cnt].c_shdr->sh_name < strtab_size) { + if (strcmp(scn_cache[cnt].c_shdr->sh_name + strtab, name) == 0) { + scn_cache[cnt].c_data = read_section_data(fd, ehdr, scn_cache[cnt].c_shdr); + return &scn_cache[cnt]; + } + } + } + + return NULL; + }
< prev index next >