]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
include, libctf: start work on libctf v4
authorNick Alcock <nick.alcock@oracle.com>
Mon, 15 Jul 2024 19:21:36 +0000 (20:21 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 28 Feb 2025 14:47:24 +0000 (14:47 +0000)
This format is a superset of BTF, but for now we just do the minimum to
declare a new file format version, without actually introducing any format
changes.

From now on, we refuse to reserialize CTFv1 dicts: these have a distinct
parent/child boundary which obviously cannot change upon reserialization
(that would change the type IDs): instead, we encoded this by stuffing in
a unique CTF version for such dicts.  We can't do that now we have one
version for all CTFv4 dicts, and testing such old dicts is very hard these
days anyway, and is not automated: so just drop support for writing them out
entirely. (You still *can* write them out, but you have to do a full-blown
ctf_link, which generates an all-new fresh dict and recomputes type IDs as
part of deduplication.)

To prevent this extremely-not-ready format escaping into the wild, add a
new mechanism whereby any format version higher than the new #define
CTF_STABLE_VERSION cannot be serialized unless I_KNOW_LIBCTF_IS_UNSTABLE is
set in the environment.

include/
* ctf-api.h (_CTF_ERRORS) [ECTF_CTFVERS_NO_SERIALIZE]: New.
        [ECTF_UNSTABLE]: New.
         (ECTF_NERR): Update.
* ctf.h: Small comment improvements..
        (ctf_header_v3): New, copy of ctf_header.
(CTF_VERSION_4): New.
(CTF_VERSION): Now CTF_VERSION_4.
(CTF_STABLE_VERSION): Still 4, CTF_VERSION_3.

ld/
* testsuite/ld-ctf/*.d: Update to CTF_VERSION_4.

libctf/
* ctf-impl.h (LCTF_NO_SERIALIZE): New.
* ctf-dump.c (ctf_dump_header): Add CTF_VERSION_4.
* ctf-open.c (ctf_dictops): Likewise.
        (upgrade_header): Rename to...
(upgrade_header_v2): ... this.
(upgrade_header_v3): New.
(upgrade_types): Support upgrading from CTF_VERSION_3.
        Turn on LCTF_NO_SERIALIZE for CTFv1.
(init_static_types_internal): Upgrade all types tables older than
* CTF_VERSION_4.
(ctf_bufopen): Support CTF_VERSION_4: error out if we forget to
update this switch in future.  Add header upgrading from v3 and
below.  Improve comments slightly.
* ctf-serialize.c (ctf_serialize): Block serialization of unstable
file formats, and of file formats for which LCTF_NO_SERIALIZE is
turned on (v1).

43 files changed:
include/ctf-api.h
include/ctf.h
ld/testsuite/ld-ctf/array-conflicted-ordering.d
ld/testsuite/ld-ctf/array-extern.d
ld/testsuite/ld-ctf/array.d
ld/testsuite/ld-ctf/conflicting-cycle-1.B-1.d
ld/testsuite/ld-ctf/conflicting-cycle-1.B-2.d
ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d
ld/testsuite/ld-ctf/conflicting-cycle-2.A-1.d
ld/testsuite/ld-ctf/conflicting-cycle-2.A-2.d
ld/testsuite/ld-ctf/conflicting-cycle-2.parent.d
ld/testsuite/ld-ctf/conflicting-cycle-3.C-1.d
ld/testsuite/ld-ctf/conflicting-cycle-3.C-2.d
ld/testsuite/ld-ctf/conflicting-cycle-3.parent.d
ld/testsuite/ld-ctf/conflicting-enums.d
ld/testsuite/ld-ctf/conflicting-typedefs.d
ld/testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d
ld/testsuite/ld-ctf/cross-tu-into-cycle.d
ld/testsuite/ld-ctf/cross-tu-noncyclic.d
ld/testsuite/ld-ctf/cycle-1.d
ld/testsuite/ld-ctf/cycle-2.A.d
ld/testsuite/ld-ctf/cycle-2.B.d
ld/testsuite/ld-ctf/cycle-2.C.d
ld/testsuite/ld-ctf/data-func-conflicted-vars.d
ld/testsuite/ld-ctf/data-func-conflicted.d
ld/testsuite/ld-ctf/diag-cttname-null.d
ld/testsuite/ld-ctf/diag-cuname.d
ld/testsuite/ld-ctf/diag-parlabel.d
ld/testsuite/ld-ctf/diag-wrong-magic-number-mixed.d
ld/testsuite/ld-ctf/enum-forward.d
ld/testsuite/ld-ctf/enums.d
ld/testsuite/ld-ctf/forward.d
ld/testsuite/ld-ctf/function.d
ld/testsuite/ld-ctf/nonrepresentable-member.d
ld/testsuite/ld-ctf/nonrepresentable.d
ld/testsuite/ld-ctf/overlapping-enums-2.d
ld/testsuite/ld-ctf/overlapping-enums.d
ld/testsuite/ld-ctf/slice.d
ld/testsuite/ld-ctf/super-sub-cycles.d
libctf/ctf-dump.c
libctf/ctf-impl.h
libctf/ctf-open.c
libctf/ctf-serialize.c

index 2bffd52b1a04f9faa87609b61d5872102b86aed9..ed01a885392574c416b601c57dc832d6e346416b 100644 (file)
@@ -244,7 +244,9 @@ typedef struct ctf_snapshot_id
   _CTF_ITEM (ECTF_NEEDSBFD, "This feature needs a libctf with BFD support.") \
   _CTF_ITEM (ECTF_INCOMPLETE, "Type is not a complete type.") \
   _CTF_ITEM (ECTF_NONAME, "Type name must not be empty.") \
-  _CTF_ITEM (ECTF_BADFLAG, "Invalid CTF dict flag specified.")
+  _CTF_ITEM (ECTF_BADFLAG, "Invalid CTF dict flag specified.") \
+  _CTF_ITEM (ECTF_CTFVERS_NO_SERIALIZE, "CTFv1 dicts are too old to serialize.") \
+  _CTF_ITEM (ECTF_UNSTABLE, "Attempt to write unstable file format version: set I_KNOW_LIBCTF_IS_UNSTABLE in the environment.")
 
 #define        ECTF_BASE       1000    /* Base value for libctf errnos.  */
 
@@ -257,7 +259,7 @@ _CTF_ERRORS
 #undef _CTF_FIRST
   };
 
-#define ECTF_NERR (ECTF_BADFLAG - ECTF_BASE + 1) /* Count of CTF errors.  */
+#define ECTF_NERR (ECTF_UNSTABLE - ECTF_BASE + 1) /* Count of CTF errors.  */
 
 /* The CTF data model is inferred to be the caller's data model or the data
    model of the given object, unless ctf_setmodel is explicitly called.  */
index 72a639ac9b431172d666962eb7d59874d2797dad..93926f1c8d4bc97b1a027557ada5b19f8df9d902 100644 (file)
@@ -138,10 +138,13 @@ extern "C"
 # define CTF_MAX_SIZE_V1       0xfffe  /* Max size of a type in bytes. */
 # define CTF_LSIZE_SENT_V1     0xffff  /* Sentinel for v1 ctt_size.  */
 
-  /* Start of actual data structure definitions.
+/* Start of actual data structure definitions.
 
-     Every field in these structures must have corresponding code in the
-     endianness-swapping machinery in libctf/ctf-open.c.  */
+   Every field in these structures must have corresponding code in the
+   endianness-swapping machinery in libctf/ctf-open.c.  */
+
+/* UPTODO: v4/BTF preamble in different order! at least the magic number is in the
+   same place.  */
 
 typedef struct ctf_preamble
 {
@@ -164,6 +167,23 @@ typedef struct ctf_header_v2
   uint32_t cth_strlen;         /* Length of string section in bytes.  */
 } ctf_header_v2_t;
 
+typedef struct ctf_header_v3
+{
+  ctf_preamble_t cth_preamble;
+  uint32_t cth_parlabel;       /* Ref to name of parent lbl uniq'd against.  */
+  uint32_t cth_parname;                /* Ref to basename of parent.  */
+  uint32_t cth_cuname;         /* Ref to CU name (may be 0).  */
+  uint32_t cth_lbloff;         /* Offset of label section.  */
+  uint32_t cth_objtoff;                /* Offset of object section.  */
+  uint32_t cth_funcoff;                /* Offset of function section.  */
+  uint32_t cth_objtidxoff;     /* Offset of object index section.  */
+  uint32_t cth_funcidxoff;     /* Offset of function index section.  */
+  uint32_t cth_varoff;         /* Offset of variable section.  */
+  uint32_t cth_typeoff;                /* Offset of type section.  */
+  uint32_t cth_stroff;         /* Offset of string section.  */
+  uint32_t cth_strlen;         /* Length of string section in bytes.  */
+} ctf_header_v3_t;
+
 typedef struct ctf_header
 {
   ctf_preamble_t cth_preamble;
@@ -196,14 +216,19 @@ typedef struct ctf_header
    writing the header from scratch, we would add a *pair* of version number
    fields to allow for this, but this will do for now.  (A flag will not do,
    because we need to encode both the version we came from and the version we
-   went to, not just "we were upgraded".) */
+   went to, not just "we were upgraded".)
 
-# define CTF_VERSION_1 1
-# define CTF_VERSION_1_UPGRADED_3 2
-# define CTF_VERSION_2 3
+   The same problem applies to v2 and v3 upgraded to v4, but here we can apply
+   some common sense and simply record the boundary in a new header field.  */
 
+#define CTF_VERSION_1 1
+#define CTF_VERSION_1_UPGRADED_3 2
+#define CTF_VERSION_2 3
 #define CTF_VERSION_3 4
-#define CTF_VERSION CTF_VERSION_3 /* Current version.  */
+
+#define CTF_VERSION_4 5
+#define CTF_VERSION CTF_VERSION_4 /* Current version.  */
+#define CTF_STABLE_VERSION 4
 
 /* All of these flags bar CTF_F_COMPRESS and CTF_F_IDXSORTED are bug-workaround
    flags and are valid only in format v3: in v2 and below they cannot occur and
index a8bbc3dd65e5d9b94e815bb71c5e0c236977e0b4..2daa67633496a490408b73ecf55ecbb526aac6c8 100644 (file)
@@ -12,7 +12,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
   Variables:
     digits_names -> .* \(kind 4\) char \*\[10\] .*
index 4c9ce784e6a60c95e612eee6b0e747ae9fb92807..c813c84894d935d3a3ba3e70bdaa4cf0e0994d30 100644 (file)
@@ -11,7 +11,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Data object section:       .* \(0x[1-9a-f][0-9a-f]* bytes\)
     Type section:      .* \(0x44 bytes\)
index 0fe675e2c5dec005656521540b3eab0a5f89aa27..8fc5a631ca81989f8357f43f08f2425a5291e8f5 100644 (file)
@@ -11,7 +11,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Data object section:       .* \(0x[1-9a-f][0-9a-f]* bytes\)
     Type section:      .* \(0x6c bytes\)
index 2ed3ce19401b24beccd4c52943f987e796092f1b..2b75e6b5f73b975579767a207dffaf05ec1a2f96 100644 (file)
@@ -15,7 +15,7 @@ CTF archive member: .*/B.c:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Parent name: .ctf
     Compilation unit name: .*/B.c
index 3b9b7f627d2232d9f7bc4b31f2bbebe1fe336ca4..c86e8718338a5950062c886630348cdddc51e0cd 100644 (file)
@@ -15,7 +15,7 @@ CTF archive member: .*/B-2.c:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Parent name: .ctf
     Compilation unit name: .*/B-2.c
index 83c56fe145c697d9b098285692bf99e2723520fc..729627299391db4e54fc288b2efaf8457904f5bb 100644 (file)
@@ -14,7 +14,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0xac bytes\)
     String section:    .*
index 6a07d368b7497777f14f1d003077804de65e8389..770ef99df8545f038aacd98ecf9c395037a07be0 100644 (file)
@@ -17,7 +17,7 @@ CTF archive member: .*/A.c:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Parent name: .*
     Compilation unit name: .*/A.c
index 677542199b0954bd9b257841b18749bf3c2de2b7..d71c5bac80cc41f0536a98da4da309db8d50d187 100644 (file)
@@ -17,7 +17,7 @@ CTF archive member: .*/A-2.c:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Parent name: .*
     Compilation unit name: .*/A-2.c
index 30be9b03ee42517b37d7576a52eea435d02643a3..f7427e32cf0b46a8501fcbf0e5a36f3fe43a87d3 100644 (file)
@@ -16,7 +16,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0x94 bytes\)
     String section:    .* \(0x1d bytes\)
index b60768fc7a798839c307f1a5deaa3d33b36c5273..6f42a495b1b3d7506b485e34e9da72d8f10a9d40 100644 (file)
@@ -16,7 +16,7 @@ CTF archive member: .*/C.c:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Parent name: .*
     Compilation unit name: .*/C.c
index 590d37348878e64f08c8aa3639a3e6ba4db39c49..55d9db623c4ce3e8a90715333d78c2c7fca6c4b8 100644 (file)
@@ -16,7 +16,7 @@ CTF archive member: .*/C-2.c:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Parent name: .*
     Compilation unit name: .*/C-2.c
index dbe2e46786f9e04090c7e75370bb2f3d7b0ced2b..e63e051fce695bc790a3ee5642fd58b5ba417a98 100644 (file)
@@ -15,7 +15,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      0x0 -- 0x57 \(0x58 bytes\)
     String section:    .*
index 4f8cf812ee486422c18c173091756fe5ecaab1d0..b334859c201fd7009dbd9bf637267bf59966ee33 100644 (file)
@@ -11,7 +11,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
   Types:
 #...
index beb1f7776c6916c71301fdff41f27954c8778f3c..4610963e8a30c31f47f47ac7b5cb1d2901593559 100644 (file)
@@ -11,7 +11,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
   Types:
     0x1: .*int .*
index c83789a996583a62c2da77f606fd3f4f8d426da8..a2018e9e8d26aeeff66e361afd1ac6afb1b6a148 100644 (file)
@@ -15,7 +15,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
 
   Labels:
index 903dedbb389e961b7a1d53e702127f9c9d4245ca..ec404a4969bbe837e44985b95f5ca8b25994a05f 100644 (file)
@@ -17,7 +17,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
 
   Labels:
index 28c2eb424595344a13af06aa12fc896db1033ec3..7e7895b2df7bdabad913d0a58d7d98585db820f0 100644 (file)
@@ -13,7 +13,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0x74 bytes\)
     String section:    .*
index 379f12f57cd75ac7d16ddd160692df58cad42fec..c01d369c13085d793b205ed6b52a1e5193ae0b9e 100644 (file)
@@ -13,7 +13,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0xa8 bytes\)
     String section:    .*
index ab3876c17d998cc63e49193eb99425da2d85ffe4..c3f17bdfcc79d7f85db93e7cee93d965a1538c1e 100644 (file)
@@ -12,7 +12,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0x6c bytes\)
     String section:    .*
index 65d702ec0366585b7addbcf8dfd7768f23c9ebee..92315b329b731eb18415b4ceb21d5fc7e16022a0 100644 (file)
@@ -12,7 +12,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0x6c bytes\)
     String section:    .*
index 81aa6dd71b22873ba5426d3b3b70c2f075d3ba22..f37e3f33e304099eb4142785a3a26fac21e099e8 100644 (file)
@@ -12,7 +12,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0x6c bytes\)
     String section:    .*
index 4e570c6a61a37a079dcdd106be24e0016b2062b1..f10fa982f70b0ab984ac7ba8e1ab7e052346e12c 100644 (file)
@@ -12,7 +12,7 @@ Contents of CTF section \.ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Data object section:       .* \(0x[1-9a-f][0-9a-f]* bytes\)
     Function info section:     .* \(0x[1-9a-f][0-9a-f]* bytes\)
@@ -41,7 +41,7 @@ CTF archive member: .*/data-func-1\.c:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Parent name: \.ctf
     Compilation unit name: .*/data-func-1\.c
index b0db511a987c34b1c293308df67fb19cf42a6fca..71f6edb04f79929962b5c747a2bd7d32e8baa34a 100644 (file)
@@ -12,7 +12,7 @@ Contents of CTF section \.ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Data object section:       .* \(0x[1-9a-f][0-9a-f]* bytes\)
     Function info section:     .* \(0x[1-9a-f][0-9a-f]* bytes\)
@@ -36,7 +36,7 @@ CTF archive member: .*/data-func-1\.c:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Parent name: \.ctf
     Compilation unit name: .*/data-func-1\.c
index 511908ea211e1010c2fdece8cb235dbd2e854db2..73933f2ca6fd8eb6f0484ec12006f2d096269218 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
   Data objects:
     a -> 0x[0-9a-f]*: \(kind 6\) struct  \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\)
index d858b5fa400085f551b55111d2b3634d35c3fc52..a2089c6b27811b7accdb82f39fa13af4a001660c 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Compilation unit name: \(\?\)
 #...
index 892970b2fb6de8aec57fe58408abce2393f47686..f69f48c97af66f5f8a48c10b8c59f95af5e1633f 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Compilation unit name: .*A.c
     Data object section:       .* \(0x[1-9a-f][0-9a-f]* bytes\)
index 668fa15bf49e26a79a6fc6cb1b225d6e2d81b185..26c3412b051b33621c532dee56e5ce4173235885 100644 (file)
@@ -11,7 +11,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Variable section:  0x0 -- 0x17 \(0x18 bytes\)
     Type section:      0x18 -- 0x83 \(0x6c bytes\)
index c53364e16fdea9ad73f107a569c7f53a7fe5888b..e26f18a31b7e955c67c74557da3390fe1cd1234e 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0x48 bytes\)
 #...
index 501c18f0b2c8ad4d2d061027bbe1a9c87fa1a09b..acc1bfc22dc070a61c568bfee95f29f2ed6480af 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Compilation unit name: .*enums.c
 #...
index 5998ecb99bd5cf9fdc6a737e909a0bac1de828d1..51412a45503dc4734fb4082dd4e54971623f4931 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Type section:      .* \(0x18 bytes\)
 #...
index 66c67eb18b46f0957191ecc597b335c83f9f0472..971b0216461129ffc61def574eae1c9a27eac77b 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Compilation unit name: .*function.c
     Function info section:     .* \(0x[1-9a-f][0-9a-f]* bytes\)
index 6c76253a8c1f02ffcb6b600c583dcfff1aada70c..b683b4898e67ccf0bf0920ad76547313cb44e07a 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
   Types:
 #...
index f02f52c46d8e47707eb6b31656f69ce5c4436716..10fe83015272caaf98d976b6cbc407479488b86e 100644 (file)
@@ -11,7 +11,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
   Function objects:
 #...
index 1adfd86b89b0fdcc1b421eddb916da1854696bc0..cf702e1962fa0c0a7e592ba82da04ac544cf1672 100644 (file)
@@ -11,7 +11,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
   Types:
     0x1: \(kind 8\) enum day_of_the_week \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\)
index 7cf57d6245200d82b1a005c68c8e8aa447abc5e7..a2e435a0576a2314e40ca90f1e88c4ae856914bf 100644 (file)
@@ -11,7 +11,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
   Types:
     0x1: \(kind 8\) enum day_of_the_week \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\)
index 838607fae731401e54d95719902d426923923c86..5567cca3eb39afab17d8a4081716e21e5db56268 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Compilation unit name: .*slice.c
 #...
index 4eb009d0225080afd7abbc73f38c7716fb82dd16..ccac9a1b8c9994cc117054aeb654d88a8f8f9585 100644 (file)
@@ -10,7 +10,7 @@ Contents of CTF section .ctf:
 
   Header:
     Magic number: 0xdff2
-    Version: 4 \(CTF_VERSION_3\)
+    Version: 5 \(CTF_VERSION_4\)
 #...
     Compilation unit name: .*super-sub-cycles.c
 #...
index 54febd644cd5aacff24a26d77147cf9a9b81c349..0c0228fdff279d8d3baa3636c146b98be723980d 100644 (file)
@@ -298,7 +298,9 @@ ctf_dump_header (ctf_dict_t *fp, ctf_dump_state_t *state)
      "CTF_VERSION_1_UPGRADED_3 (latest format, version 1 type "
      "boundaries)",
      "CTF_VERSION_2",
-     "CTF_VERSION_3", NULL
+     "CTF_VERSION_3",
+     "CTF_VERSION_4",
+     NULL
     };
   const char *verstr = NULL;
 
index b40c8679c4a2318e77d535580bc5131ad9c0178d..c4eeb9e50929ae65d000154f813f7ea7707a5702 100644 (file)
@@ -602,8 +602,8 @@ struct ctf_next
   ((fp)->ctf_dictops->ctfo_get_vbytes(fp, kind, size, vlen))
 
 #define LCTF_CHILD     0x0001  /* CTF dict is a child.  */
-#define LCTF_LINKING   0x0002  /* CTF link is underway: respect ctf_link_flags.  */
 #define LCTF_STRICT_NO_DUP_ENUMERATORS 0x0004 /* Duplicate enums prohibited.  */
+#define LCTF_NO_SERIALIZE      0x0010  /* Serialization of this dict prohibited.  */
 
 extern ctf_dynhash_t *ctf_name_table (ctf_dict_t *, int);
 extern const ctf_type_t *ctf_lookup_by_id (ctf_dict_t **, ctf_id_t);
index 449728fc3f4e22e340169da459d9c0fff98d7a83..0d2a956f4a8716af2e700fdc93c7cf21e90f12ce 100644 (file)
@@ -215,6 +215,8 @@ static const ctf_dictops_t ctf_dictops[] = {
   {get_kind_v2, get_root_v2, get_vlen_v2, get_ctt_size_v2, get_vbytes_v2},
   /* CTF_VERSION_3, identical to 2: only new type kinds */
   {get_kind_v2, get_root_v2, get_vlen_v2, get_ctt_size_v2, get_vbytes_v2},
+  /* UPTODO: CTF_VERSION_4, identical to 3 at present (but not for long) */
+  {get_kind_v2, get_root_v2, get_vlen_v2, get_ctt_size_v2, get_vbytes_v2},
 };
 
 /* Initialize the symtab translation table as appropriate for its indexing
@@ -394,9 +396,10 @@ ctf_set_version (ctf_dict_t *fp, ctf_header_t *cth, int ctf_version)
 }
 
 
-/* Upgrade the header to CTF_VERSION_3.  The upgrade is done in-place.  */
+/* Upgrade the header to CTF_VERSION_4.  The upgrade is done in-place,
+   end-to-start.  */
 static void
-upgrade_header (ctf_header_t *hp)
+upgrade_header_v2 (ctf_header_t *hp)
 {
   ctf_header_v2_t *oldhp = (ctf_header_v2_t *) hp;
 
@@ -412,6 +415,26 @@ upgrade_header (ctf_header_t *hp)
   hp->cth_cuname = 0;                          /* No CU name.  */
 }
 
+/* Ditto, for CTFv3.  */
+static void
+upgrade_header_v3 (ctf_header_t *hp)
+{
+  ctf_header_v3_t *oldhp = (ctf_header_v3_t *) hp;
+
+  hp->cth_strlen = oldhp->cth_strlen;
+  hp->cth_stroff = oldhp->cth_stroff;
+  hp->cth_typeoff = oldhp->cth_typeoff;
+  hp->cth_varoff = oldhp->cth_varoff;
+  hp->cth_funcidxoff = oldhp->cth_funcidxoff;
+  hp->cth_objtidxoff = oldhp->cth_objtidxoff;
+  hp->cth_funcoff = oldhp->cth_funcoff;
+  hp->cth_objtoff = oldhp->cth_objtoff;
+  hp->cth_lbloff = oldhp->cth_lbloff;
+  hp->cth_cuname = oldhp->cth_cuname;
+  hp->cth_parname = oldhp->cth_parname;
+  hp->cth_parlabel = oldhp->cth_parlabel;
+}
+
 /* Upgrade the type table to CTF_VERSION_3 (really CTF_VERSION_1_UPGRADED_3)
    from CTF_VERSION_1.
 
@@ -661,10 +684,15 @@ upgrade_types (ctf_dict_t *fp, ctf_header_t *cth)
 
     case CTF_VERSION_1_UPGRADED_3:
       fp->ctf_parmax = CTF_MAX_PTYPE_V1;
+      fp->ctf_flags |= LCTF_NO_SERIALIZE;
+      break;
+
+      /* v2 and v3 are currently just the same as v4 except for new types and
+        sections: no upgrading required.
 
-      /* v2 is just the same as v3 except for new types and sections:
-        no upgrading required. */
+        UPTODO: this is really going to change.  */
     case CTF_VERSION_2: ;
+    case CTF_VERSION_3: ;
       /* FALLTHRU */
     }
   return 0;
@@ -724,7 +752,7 @@ init_static_types_internal (ctf_dict_t *fp, ctf_header_t *cth,
   int nlstructs = 0, nlunions = 0;
   int err;
 
-  if (_libctf_unlikely_ (fp->ctf_version == CTF_VERSION_1))
+  if (fp->ctf_version < CTF_VERSION_4)
     {
       int err;
       if ((err = upgrade_types (fp, cth)) != 0)
@@ -1463,7 +1491,7 @@ ctf_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
     }
 
   if (_libctf_unlikely_ ((pp->ctp_version < CTF_VERSION_1)
-                        || (pp->ctp_version > CTF_VERSION_3)))
+                        || (pp->ctp_version > CTF_VERSION_4)))
     return (ctf_set_open_errno (errp, ECTF_CTFVERS));
 
   if ((symsect != NULL) && (pp->ctp_version < CTF_VERSION_2))
@@ -1478,8 +1506,24 @@ ctf_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
       return (ctf_set_open_errno (errp, ECTF_NOTSUP));
     }
 
-  if (pp->ctp_version < CTF_VERSION_3)
-    hdrsz = sizeof (ctf_header_v2_t);
+  switch (pp->ctp_version)
+    {
+    case CTF_VERSION_1:
+    case CTF_VERSION_2:
+      hdrsz = sizeof (ctf_header_v2_t);
+      break;
+    case CTF_VERSION_1_UPGRADED_3:
+    case CTF_VERSION_3:
+      hdrsz = sizeof (ctf_header_v3_t);
+      break;
+    case CTF_VERSION_4:
+      hdrsz = sizeof (ctf_header_t);
+      break;
+    default:
+      ctf_err_warn (NULL, ECTF_INTERNAL, 0, "ctf_bufopen: CTF version %d "
+                   "not handled in header-length switch", pp->ctp_version);
+      return (ctf_set_open_errno (errp, ECTF_INTERNAL));
+    }
 
   if (_libctf_unlikely_ (pp->ctp_flags > CTF_F_MAX))
     {
@@ -1489,6 +1533,8 @@ ctf_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
       return (ctf_set_open_errno (errp, ECTF_FLAGS));
     }
 
+  /* UPTODO: v4 flags: none valid, new header field likely needed.  */
+
   if (ctfsect->cts_size < hdrsz)
     return (ctf_set_open_errno (errp, ECTF_NOCTFBUF));
 
@@ -1505,7 +1551,11 @@ ctf_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
   hp = fp->ctf_header;
   memcpy (hp, ctfsect->cts_data, hdrsz);
   if (pp->ctp_version < CTF_VERSION_3)
-    upgrade_header (hp);
+    upgrade_header_v2 (hp);
+  else if (pp->ctp_version < CTF_VERSION_4)
+    upgrade_header_v3 (hp);
+
+  /* UPTODO: header "upgrade" from BTF -> CTFv4.  */
 
   if (foreign_endian)
     ctf_flip_header (hp);
@@ -1546,7 +1596,7 @@ ctf_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
       return (ctf_set_open_errno (errp, ECTF_CORRUPT));
     }
 
-  /* This invariant will be lifted in v4, but for now it is true.  */
+  /* This invariant may be lifted in v5, but for now it is true.  */
 
   if ((hp->cth_funcidxoff - hp->cth_objtidxoff != 0) &&
       (hp->cth_funcidxoff - hp->cth_objtidxoff
@@ -1581,6 +1631,9 @@ ctf_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
   /* Note: if this is a v1 buffer, it will be reallocated and expanded by
      init_static_types().  */
 
+  /* UPTODO: may need to try unconditionally for BTF, and get flags from
+     somewhere else.  */
+
   if (hp->cth_flags & CTF_F_COMPRESS)
     {
       size_t srclen;
@@ -1678,7 +1731,7 @@ ctf_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
       goto bad;
     }
 
-  fp->ctf_parmax = CTF_MAX_PTYPE;
+  fp->ctf_parmax = CTF_MAX_PTYPE;              /* May be reset by upgrade_types.  */
   memcpy (&fp->ctf_data, ctfsect, sizeof (ctf_sect_t));
 
   if (symsect != NULL)
index 8c35a2b2489635134aad83d8c6a2af556fa7f103..5c7190ec8f3a0005f4c613e80cc9204f67839e78 100644 (file)
@@ -961,9 +961,28 @@ ctf_serialize (ctf_dict_t *fp, size_t *bufsiz)
   emit_symtypetab_state_t symstate;
   memset (&symstate, 0, sizeof (emit_symtypetab_state_t));
 
-  /* Fill in an initial CTF header.  We will leave the label, object,
-     and function sections empty and only output a header, type section,
-     and string table.  The type section begins at a 4-byte aligned
+  /* Stop unstable file formats (subject to change) getting out into the
+     wild.  */
+#if CTF_VERSION != CTF_STABLE_VERSION
+  if (!getenv ("I_KNOW_LIBCTF_IS_UNSTABLE"))
+    {
+      ctf_set_errno (fp, ECTF_UNSTABLE);
+      return NULL;
+    }
+#endif
+
+  /* Prohibit reserialization of dicts for which we have dynamic state inherited
+     from the upgrade process which we cannot record in the dict.  Right now,
+     this applies only to CTFv1 dicts, which have a different parent/child type
+     offset to v2 and higher, and nowhere to record this in CTFv4.  */
+
+  if (fp->ctf_flags & LCTF_NO_SERIALIZE)
+    {
+      ctf_set_errno (fp, ECTF_CTFVERS_NO_SERIALIZE);
+      return NULL;
+    }
+
+  /* Fill in an initial CTF header.  The type section begins at a 4-byte aligned
      boundary past the CTF header itself (at relative offset zero).  The flag
      indicating a new-style function info section (an array of CTF_K_FUNCTION
      type IDs in the types section) is flipped on.  */
@@ -974,6 +993,8 @@ ctf_serialize (ctf_dict_t *fp, size_t *bufsiz)
 
   /* This is a new-format func info section, and the symtab and strtab come out
      of the dynsym and dynstr these days.  */
+
+  /* UPTODO: remove.  */
   hdr.cth_flags = (CTF_F_NEWFUNCINFO | CTF_F_DYNSTR);
 
   /* Propagate all symbols in the symtypetabs into the dynamic state, so that