diff --git a/btf_encoder.c b/btf_encoder.c
index 1b4e83d..c341f95 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -141,6 +141,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
 	[BTF_KIND_VAR]          = "VAR",
 	[BTF_KIND_DATASEC]      = "DATASEC",
 	[BTF_KIND_FLOAT]        = "FLOAT",
+	[BTF_KIND_TAG]          = "TAG",
 };
 
 static const char *btf__printable_name(const struct btf *btf, uint32_t offset)
@@ -644,6 +645,26 @@ static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char
 	return id;
 }
 
+static int32_t btf_encoder__add_tag(struct btf_encoder *encoder, const char *value, uint32_t type,
+				    int component_idx)
+{
+	struct btf *btf = encoder->btf;
+	const struct btf_type *t;
+	int32_t id;
+
+	id = btf__add_tag(btf, value, type, component_idx);
+	if (id > 0) {
+		t = btf__type_by_id(btf, id);
+		btf_encoder__log_type(encoder, t, false, true, "type_id=%u component_idx=%d",
+				      t->type, component_idx);
+	} else {
+		btf__log_err(btf, BTF_KIND_TAG, value, true, "component_idx=%d Error emitting BTF type",
+			     component_idx);
+	}
+
+	return id;
+}
+
 /*
  * This corresponds to the same macro defined in
  * include/linux/kallsyms.h
@@ -1158,6 +1179,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct
 		struct variable *var = tag__variable(pos);
 		uint32_t size, type, linkage;
 		const char *name, *dwarf_name;
+		struct llvm_annotation *annot;
 		const struct tag *tag;
 		uint64_t addr;
 		int id;
@@ -1244,6 +1266,15 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct
 			goto out;
 		}
 
+		list_for_each_entry(annot, &var->annots, node) {
+			int tag_type_id = btf_encoder__add_tag(encoder, annot->value, id, annot->component_idx);
+			if (tag_type_id < 0) {
+				fprintf(stderr, "error: failed to encode tag '%s' to variable '%s' with component_idx %d\n",
+					annot->value, name, annot->component_idx);
+				goto out;
+			}
+		}
+
 		/*
 		 * add a BTF_VAR_SECINFO in encoder->percpu_secinfo, which will be added into
 		 * encoder->types later when we add BTF_VAR_DATASEC.
@@ -1359,6 +1390,8 @@ void btf_encoder__delete(struct btf_encoder *encoder)
 int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
 {
 	uint32_t type_id_off = btf__get_nr_types(encoder->btf);
+	struct llvm_annotation *annot;
+	int btf_type_id, tag_type_id;
 	uint32_t core_id;
 	struct function *fn;
 	struct tag *pos;
@@ -1378,7 +1411,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
 	}
 
 	cu__for_each_type(cu, core_id, pos) {
-		int32_t btf_type_id = btf_encoder__encode_tag(encoder, pos, type_id_off);
+		btf_type_id = btf_encoder__encode_tag(encoder, pos, type_id_off);
 
 		if (btf_type_id < 0 ||
 		    tag__check_id_drift(pos, core_id, btf_type_id, type_id_off)) {
@@ -1396,6 +1429,25 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
 		encoder->has_index_type = true;
 	}
 
+	cu__for_each_type(cu, core_id, pos) {
+		struct namespace *ns;
+
+		if (pos->tag != DW_TAG_structure_type && pos->tag != DW_TAG_union_type)
+			continue;
+
+		btf_type_id = type_id_off + core_id;
+		ns = tag__namespace(pos);
+		list_for_each_entry(annot, &ns->annots, node) {
+			tag_type_id = btf_encoder__add_tag(encoder, annot->value, btf_type_id, annot->component_idx);
+			if (tag_type_id < 0) {
+				fprintf(stderr, "error: failed to encode tag '%s' to %s '%s' with component_idx %d\n",
+					annot->value, pos->tag == DW_TAG_structure_type ? "struct" : "union",
+					namespace__name(ns), annot->component_idx);
+				goto out;
+			}
+		}
+	}
+
 	cu__for_each_function(cu, core_id, fn) {
 		int btf_fnproto_id, btf_fn_id;
 		const char *name;
@@ -1436,6 +1488,15 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
 			printf("error: failed to encode function '%s'\n", function__name(fn));
 			goto out;
 		}
+
+		list_for_each_entry(annot, &fn->annots, node) {
+			tag_type_id = btf_encoder__add_tag(encoder, annot->value, btf_fn_id, annot->component_idx);
+			if (tag_type_id < 0) {
+				fprintf(stderr, "error: failed to encode tag '%s' to func %s with component_idx %d\n",
+					annot->value, name, annot->component_idx);
+				goto out;
+			}
+		}
 	}
 
 	if (!encoder->skip_encoding_vars)
