From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25D003EDAB5 for ; Mon, 1 Jun 2026 18:35:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780338925; cv=none; b=b+FKMnMbUVgGOn2j54vW9leJshnqa2KCPRrK3yT2VIU+h+43hBi2WGhh1/4nTRLDxOvyu9mj23Ru0oJxs1NnAWYHTBr4Fba1FbFmVOkwtG0OhhJ3kg5Tkt6T6CS2xKyd5VZqGqoXahCGCNeBYEFQ6qU+gXQSUUXfOxIsPGtJjFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780338925; c=relaxed/simple; bh=rzNYfCVd4VyGmm+4pmOLHdgbgeONw++P6WQ8Wn8hnns=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cOtWHZ3SpK5U7XvWf+3Y3GGOZ4FddHtL1s8n3kn3vyNmACxtfc4uxpFJuw45aMnkkfGT6gcDkKtEfORxwd/rXiPlDvYqG12shvHa5CZCoe7aU1UNaXmYTMgH8awkPKBi9SFnCv9rNzfRFOE7ayo1Z2PJnsmzJov03hsstU8EBHo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=pQZ1+yrx; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pQZ1+yrx" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780338920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=G11kVTgeG4Bceb+ehzyecPZsVsSNBd8mkyLStQA5/T4=; b=pQZ1+yrxMFaXAaZyYhnvJt7vXj8Os4W8m60Is3qW8rw6nQKXVfgPoAl1xA8Owwr60peQK7 USCnQAZWQ3xYdu1FeXPr4sxqsYvbJAtHsYcm5Jwt5coDW2Erq8xJqfIKbh8ddIYEcV8LTq tjMiaNHTk7gLIQrA62E1T0WxXRe/3IY= From: Vineet Gupta To: dwarves@vger.kernel.org Cc: bpf@vger.kernel.org, Andrii Nakryiko , acme@kernel.org, Alan Maguire , jose.marchesi@oracle.com, David Faust , Vineet Gupta Subject: [PAHOLE v3 1/3] dwarf_loader: Extract die__add_btf_type_tag() helper Date: Mon, 1 Jun 2026 11:35:09 -0700 Message-ID: <20260601183511.594100-1-vineet.gupta@linux.dev> Precedence: bulk X-Mailing-List: dwarves@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT NFC change preparing for DW_TAG_GNU_annotation support. Extract the btf_type_tag annotation creation logic from into a helper die__add_btf_type_tag(). Signed-off-by: Vineet Gupta --- Changes since v2 [2] - die__add_btf_type_tag() returns pointer not error code. Changes since v1 [1] - NFC reinstate some original comments [2] https://lore.kernel.org/bpf/20260528223616.2035618-1-vineet.gupta@linux.dev/ [1] https://lore.kernel.org/bpf/20260526181818.4159927-1-vineet.gupta@linux.dev/ --- dwarf_loader.c | 57 +++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 16fb7becffee..8b5b526299b5 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -1600,14 +1600,43 @@ static struct btf_type_tag_type *die__create_new_btf_type_tag_type(Dwarf_Die *di return tag; } +static struct btf_type_tag_ptr_type *die__add_btf_type_tag(struct btf_type_tag_ptr_type *tag, + Dwarf_Die *die, Dwarf_Die *adie, + struct cu *cu, struct conf_load *conf) +{ + struct btf_type_tag_type *annot; + uint32_t id; + + if (tag == NULL) { + tag = die__create_new_btf_type_tag_ptr_type(die, cu); + if (!tag) + return NULL; + } + + annot = die__create_new_btf_type_tag_type(adie, cu, conf); + if (annot == NULL) + return NULL; + + if (cu__table_add_tag(cu, &annot->tag, &id) < 0) + return NULL; + + struct dwarf_tag *dtag = tag__dwarf(&annot->tag); + dtag->small_id = id; + cu__hash(cu, &annot->tag); + + /* Prepends: for annotations tag1 -> tag2 -> tag3, + * the tag->tags list ends up as tag3 -> tag2 -> tag1. + */ + list_add(&annot->node, &tag->tags); + return tag; +} + static struct tag *die__create_new_pointer_tag(Dwarf_Die *die, struct cu *cu, struct conf_load *conf) { struct btf_type_tag_ptr_type *tag = NULL; - struct btf_type_tag_type *annot; Dwarf_Die *cdie, child; const char *name; - uint32_t id; /* If no child tags or skipping btf_type_tag encoding, just create a new tag * and return @@ -1627,29 +1656,9 @@ static struct tag *die__create_new_pointer_tag(Dwarf_Die *die, struct cu *cu, if (strcmp(name, "btf_type_tag") != 0) continue; - if (tag == NULL) { - /* Create a btf_type_tag_ptr type. */ - tag = die__create_new_btf_type_tag_ptr_type(die, cu); - if (!tag) - return NULL; - } - - /* Create a btf_type_tag type for this annotation. */ - annot = die__create_new_btf_type_tag_type(cdie, cu, conf); - if (annot == NULL) - return NULL; - - if (cu__table_add_tag(cu, &annot->tag, &id) < 0) + tag = die__add_btf_type_tag(tag, die, cdie, cu, conf); + if (tag == NULL) return NULL; - - struct dwarf_tag *dtag = tag__dwarf(&annot->tag); - dtag->small_id = id; - cu__hash(cu, &annot->tag); - - /* For a list of DW_TAG_LLVM_annotation like tag1 -> tag2 -> tag3, - * the tag->tags contains tag3 -> tag2 -> tag1. - */ - list_add(&annot->node, &tag->tags); } while (dwarf_siblingof(cdie, cdie) == 0); return tag ? &tag->tag : tag__new(die, cu); -- 2.54.0