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 154BC6ECE3; Mon, 4 Jul 2022 00:38:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 154BC6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1656884335; bh=UbUdoB1Dk6RBzcQARVj93oJ5B9SP7OPritUUPQ4FtsA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HaSCxOEWNtyS5Mq8tC0PKYnCPfnYl+1VzU0kwzvy+giX+mOV/0jHT9Yrad437/7g+ alOrACj6VfoJG4cWsxF6aFoTDzubjXVsExInhMt/ZagqYR0RBnXUgtFK1tIrhHEYDD 2+0JkLduH5TeKyBNY2LXqZYfGdKsq9WErDTidYHc= Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 674CB6ECE4 for ; Mon, 4 Jul 2022 00:38:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 674CB6ECE4 Received: by mail-lj1-f176.google.com with SMTP id b19so8902342ljf.6 for ; Sun, 03 Jul 2022 14:38:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N3PWgQPNr/EUWMkgIJ6YPni0LBoMql2x1DlebOR3eqI=; b=ctqKlji0dQOBBxM8xkqQbK3yXf7rIFfq6B+qYcPYMMkRgrhSRTtray/O0DHm4xPRsx GlOgrVAf/YvmgjNytKdVGRjM7a8cPk1SrXEIjcvJ/yzy18GydcIKRnLQvzgl/6tzJBcY TfEmOKk/61DsCKrFrqa5HrzyRFTPpNW7vRgO2RyqgOcZAkxDOrV3klL7IOnXrYMrDpRp nLPNOsqePrmKRitDaGNDrMVqc03cex5qwPnX20CMRz7SMx9q+vE5/MjDsIxhxUKJNKai rrxeXfjXMNWC0uN5RkLvapZfz1UHW30/GM5wC2Irc+FrL3IxygNf2CN6ATDvfP4iIn0V 0/yw== X-Gm-Message-State: AJIora9B05HfW/NXoKJgutTzkF5iLjBC/oXPYjy5zqcqPH7gJZJH/Xv/ OmFRSGycykBi9taOLe5OcMuWnx4sxIipFM3zc+I= X-Google-Smtp-Source: AGRyM1tMv448780Aev6iq6/QZNtHWnMFMOtulxk6HaiLmS0q6ruM6RGlvMf40YfG+Mxh2og3eJDZqQ== X-Received: by 2002:a2e:918f:0:b0:25a:7164:f408 with SMTP id f15-20020a2e918f000000b0025a7164f408mr14606415ljg.523.1656884304787; Sun, 03 Jul 2022 14:38:24 -0700 (PDT) Received: from localhost.localdomain ([2a00:1370:8176:4756:d639:b1a3:1b97:ec28]) by smtp.gmail.com with ESMTPSA id u11-20020a05651220cb00b0047faa01edd9sm4870480lfr.229.2022.07.03.14.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jul 2022 14:38:24 -0700 (PDT) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Mon, 4 Jul 2022 00:38:14 +0300 Message-Id: <56629a2a9ec830a80fef615d3848ef3535bf2b2b.1656883823.git.m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [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: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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, 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] = ""; 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) { + if (-1 != readlink("/proc/self/exe", executable_path, PATH_MAX)) + 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