From nobody Tue Apr 09 11:15:23 2024 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VDNfm57zfz5Glq7 for ; Tue, 9 Apr 2024 11:15:28 +0000 (UTC) (envelope-from alas.20073@gmail.com) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VDNfl53W0z4lWN for ; Tue, 9 Apr 2024 11:15:27 +0000 (UTC) (envelope-from alas.20073@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=QUrcdrNU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of alas.20073@gmail.com designates 2a00:1450:4864:20::434 as permitted sender) smtp.mailfrom=alas.20073@gmail.com Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-343c7fae6e4so3640346f8f.1 for ; Tue, 09 Apr 2024 04:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712661326; x=1713266126; darn=freebsd.org; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Ftocq0AG9r7iLRUmfmDyoCTX/OWB1unbeV3sokYA+hM=; b=QUrcdrNUtC3FDGP5lSdInXcS3O/gmRleCHsmVwt3mwpY68Bvh099De1e8esdngXymM c7E31obkNyK7/9F6eXJyBvsTtVGV58D9ywo9kd1mJBOLJiMmbOOzbItzm+DoSAHSib+n LyqPm5Ljif62Qo1InO+bNQKqzXyb5tXQ8MuDCv3+9r69OLpbUe9RWIDVhquTRSTklEC1 G/GFNlrReT/wVGLr3DaaCA2gf800jayTeqYhRSd+/5bDkZVfdUJVz1r9mi+NF0dyXSdT vS1xP6XUpcN4skIbU96M30WqPjvO7rvzXA+A+Fuv9LKBp3KbPh5au+BiAjaNXKUPafo+ zMPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712661326; x=1713266126; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ftocq0AG9r7iLRUmfmDyoCTX/OWB1unbeV3sokYA+hM=; b=o9rFE5pO4rMCGOyuLJCtz3yxPJKYZ/rjDLGthpoE6I9bTkH6/H8eB42qEY75mCWcot gjeulNpIWH2mPp3APSKREaODOcMMPZZLaXf3MNP6DKuPgEDuuW9xJl6acXJTsSZgs37C 3vz5C5aHucZwinwq4pNAZiPGRt9I/FiFFe5ja9RkBqyCAehNakyWqFPAo3di7J9KIyIa yDqQJvS9ENZG6wMrDvkCJ63UuRYwZvshUKX0sJ/CBoWKEqwLsuIHpQ9VLC1c3XFvz6GY 4AHu/2Z4aohNtPFJTQFOHACHnNLnrVrWPdGOqA/doxd6kQitTRzjiZo0/5BPAGIjHKe1 cpGA== X-Gm-Message-State: AOJu0Yx6HmkZvr2XZzfCPrskNIhi72e+fbWkMJp1v1YGc0OuqF92TnZH 4CrMhK/TTrK3c6L88aH794WKaO3wct7imz3QafARbtcsSKZLLwUApN+vMyfQ X-Google-Smtp-Source: AGHT+IFB2yIkxTs0nMqYg5a5CpOyUA+KPAY+JSQIzsk4XJiQoQlh71GCMzizHyT6R9jXznmm1VFIGA== X-Received: by 2002:adf:a486:0:b0:33e:bfd0:41f9 with SMTP id g6-20020adfa486000000b0033ebfd041f9mr7695560wrb.31.1712661325710; Tue, 09 Apr 2024 04:15:25 -0700 (PDT) Received: from [10.40.251.181] (pc207-181.public.smd.kcl.ac.uk. [193.61.207.181]) by smtp.gmail.com with ESMTPSA id r12-20020a5d498c000000b00343e8968917sm10790430wrq.1.2024.04.09.04.15.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Apr 2024 04:15:25 -0700 (PDT) Message-ID: Date: Tue, 9 Apr 2024 12:15:23 +0100 List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Andrei Lascu Subject: Questions about a symbol in `libc.so` To: freebsd-questions@freebsd.org Content-Language: en-GB Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Bar: --- X-Spamd-Result: default: False [-3.97 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.98)[-0.979]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36:c]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; ARC_NA(0.00)[]; TAGGED_FROM(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; MID_RHS_MATCH_FROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-questions@freebsd.org]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::434:from] X-Rspamd-Queue-Id: 4VDNfl53W0z4lWN Hello. Due to certain circumstances, I am currently working on a loader-like application for shared object files to be ran on a system running an OS derived from FreeBSD. I've got most of the stuff working to the level I need, but I've found something in `libc.so.7` that's got me stumped. The goal is to run a test file that, among others, calls `fdopen` from `libc.so`. Everything runs well, until line 124 in `findfp.c` is hit (as per the source for `libc.so` in FreeBSD 14 Stable), where `__sdidinit` is accessed. In my loader, there is no memory allocated for this variable, because there is no relocation entry for it. Here is where my confusion starts. Looking at the symbol table for `libc.so`, `__sdidinit` is a `LOCAL DEFAULT` [1] symbol. The only way I can think of to replicate that behaviour is to declare a variable static. However, the variable is declared as `int __sdidinit` in `findfp.c` (and also as `extern int __sdidinit` in `stdio/local.h`, which again, looks odd), which to me should mean it's a `GLOBAL` symbol (unless there is some weird linking stuff I didn't manage to hunt down during compilation). Furthermore, running the program through the system runtime loader (and also looking at the compiled assembly), accessing the variable seems to be done to what I 90% believe is a GOT lookup. However, with no relocation entry, I'm completely unsure how this is the case. My questions are as follows: 1) Is it possible to access a variable via a GOT lookup when a relocation entry does not exist? 2) Is there some explanation as to how this variable gets `LOCAL` binding? 3) Is perhaps the system loader doing some special thing because it considers `libc.so` especially, and it brings some relocation entries from somewhere else, or has some default ones? 4) A side question: while the symbol exists in `libc.so.7.full`, after doing a `make buildworld`, it seems to be stripped out of `libc.so.7` itself - I'm wondering if this is some optimization at work. Thanks in advance for your help, and apologies if this was the wrong mailing list to ask. Regards, Andrei. [1] I should mention I had a look at OpenBSD's `libc.so`, which was the other `libc.so` that I found with this symbol. In there, the main difference is that `__sdidinit` is `LOCAL HIDDEN`, which, if some similar mechanism might be employed in FreeBSD, might explain 2) and 4) above, but I'm still unsure where to look.