From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 287736ECE3; Sat, 16 Jul 2022 10:23:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 287736ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1657956218; bh=7XtlRfGYF59foQcvmkXErteovVs7bw6Y4czEFqHEU1o=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=sTxyq7jpgvd1sQjoXuFwVOTVN5pi9PzhtrQ0WcCS2rgTNvdm1BtidygL3KhlWr18H yN5AEfksHu27CI/cPwzZGfa7UpXOp5v2IWJO2dWR1PLU6rA+GEDszWAga5hwv6V631 yGvZNvRQLKXoV42fLwAK3VR4IyTmRk+2FEE4iLMg= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4DD746ECE3 for ; Sat, 16 Jul 2022 10:23:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4DD746ECE3 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1oCc9H-0000mK-9o; Sat, 16 Jul 2022 10:23:35 +0300 Date: Sat, 16 Jul 2022 10:21:13 +0300 To: Maxim Kokryashkin Message-ID: References: <56629a2a9ec830a80fef615d3848ef3535bf2b2b.1656883823.git.m.kokryashkin@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56629a2a9ec830a80fef615d3848ef3535bf2b2b.1656883823.git.m.kokryashkin@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD97CF746166DCF1A1461E6730090955D9C3BFDF8A115AF2A08182A05F538085040CD5ED3F71A977C811366B5677786B46B1DDCB4D730DF4AF0D3D430726A71C0B4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E2331B2371EFE129EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379A70878BADDF00B98638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D877A0A0696E09C5AE69457E0CB910C847117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC6BA66BB79834B351A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6AC294AFEFA671E80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B0D4C601CEA03E70EED71D610BA8056A108F1851E99FBCE2CBA07F3FCA958A8F629C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34E20F2278F74481A14EE119B4C51DCDCF7AB867DF2ACE8FCD8B921F194FA22E40AF644974FE871AD71D7E09C32AA3244C42164C182266CC51F4CB1C38E60C1378C3B3ADDA61883BB5927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj/I4vCLMdMHChah7od+AqGg== X-Mailru-Sender: 689FA8AB762F7393CC2E0F076E87284E0DC8F79FD5E2631B4EE719440E10BAD30FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] symtab: fix static symtab dump X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maxim! Thanks for the patch! LGTM, with several comments below. On 04.07.22, Maxim Kokryashkin wrote: > The `dl_iterate_phdr` returns an empty string as a name for > the executable from which it was called. Don't get: why it is the problem? I.e. why it is problem to obtain the main symbol table? Is it sysprof parser restrictions? > It is still possible > to access its dynamic symbol table, but it is vital for > sysprof to obtain the main symbol table for the LuaJIT > executable. To do so, we need a valid path to the executable. > > Since there is no way to obtain the path to a running executable > using the C standard library, this commit adds call to > `readlink` to gather the symbolic link from `/proc/self/exe`. > Most of the UNIX-based systems have procfs, so it is not > a problem. > > Needed for tarantool/tarantool#7244 > --- > src/lj_symtab.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/src/lj_symtab.c b/src/lj_symtab.c > index 2b2b205b..23696401 100644 > --- a/src/lj_symtab.c > +++ b/src/lj_symtab.c > @@ -16,10 +16,12 @@ > > #if LJ_HASRESOLVER > > +#include > #include > #include > #include > #include > +#include > #include "lj_gc.h" > #endif > > @@ -352,6 +354,7 @@ static int resolve_symbolnames(struct dl_phdr_info *info, size_t info_size, > struct lj_wbuf *buf = conf->buf; > lua_State *L = conf->L; > const uint8_t header = conf->header; > + char executable_path[PATH_MAX] = ""; Why do we need this initialization? ^ > > uint32_t lib_cnt = 0; > > @@ -387,6 +390,31 @@ static int resolve_symbolnames(struct dl_phdr_info *info, size_t info_size, > ** Main way: try to open ELF and read SHT_SYMTAB, SHT_STRTAB and SHT_HASH > ** sections from it. > */ > + > + /* > + ** The `dl_iterate_phdr` returns an empty string as a name for > + ** the executable from which it was called. It is still possible to > + ** access its dynamic symbol table, but it is vital for sysprof to obtain > + ** the main symbol table for the LuaJIT executable. To do so, we need a > + ** valid path to the executable. Since there is no way to obtain the > + ** path to a running executable using the C standard library, the only > + ** more or less reliable way to do this is by reading the symbolic link > + ** from `/proc/self/exe`. Most of the UNIX-based systems have procfs, so > + ** it is not a problem. > + */ > + if (*info->dlpi_name == 0) { Nit: s/0/'\0'/ to emphasize that we check that string contains only NULL char. > + if (-1 != readlink("/proc/self/exe", executable_path, PATH_MAX)) Nit: `readlink("/proc/self/exe", executable_path, PATH_MAX) != -1` > + info->dlpi_name = executable_path; > + else > + /* > + ** It is impossible for sysprof to function properly without the > + ** LuaJIT's .symtab section present. The assertion below > + ** is unlikely to be triggered on any system supported by sysprof, > + ** unless someone have deleted the LuaJIT binary right after the > + ** start. > + */ > + lua_assert(0); > + } > if (dump_sht_symtab(info->dlpi_name, buf, L, header, info->dlpi_addr) == 0) { > ++conf->cur_lib; > } > -- > 2.36.1 > -- Best regards, Sergey Kaplun