diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2024-07-15 20:21:36 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2024-11-18 11:50:01 +0000 |
commit | 11766c25f075c496cc1aef17852a7a2522f7df39 (patch) | |
tree | 6b1a84e6719c8136b8d986ae67447b3e43b881b6 | |
parent | 335cb88259f60a50b96da84c90559ec6a149eb04 (diff) | |
download | binutils-11766c25f075c496cc1aef17852a7a2522f7df39.zip binutils-11766c25f075c496cc1aef17852a7a2522f7df39.tar.gz binutils-11766c25f075c496cc1aef17852a7a2522f7df39.tar.bz2 |
include, libctf: start work on libctf v4
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, 168 insertions, 65 deletions
diff --git a/include/ctf-api.h b/include/ctf-api.h index dd719d1..61a70a0 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -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. */ diff --git a/include/ctf.h b/include/ctf.h index f188202..75d2ed2 100644 --- a/include/ctf.h +++ b/include/ctf.h @@ -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 diff --git a/ld/testsuite/ld-ctf/array-conflicted-ordering.d b/ld/testsuite/ld-ctf/array-conflicted-ordering.d index a8bbc3d..2daa676 100644 --- a/ld/testsuite/ld-ctf/array-conflicted-ordering.d +++ b/ld/testsuite/ld-ctf/array-conflicted-ordering.d @@ -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\] .* diff --git a/ld/testsuite/ld-ctf/array-extern.d b/ld/testsuite/ld-ctf/array-extern.d index 4c9ce78..c813c84 100644 --- a/ld/testsuite/ld-ctf/array-extern.d +++ b/ld/testsuite/ld-ctf/array-extern.d @@ -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\) diff --git a/ld/testsuite/ld-ctf/array.d b/ld/testsuite/ld-ctf/array.d index 0fe675e..8fc5a63 100644 --- a/ld/testsuite/ld-ctf/array.d +++ b/ld/testsuite/ld-ctf/array.d @@ -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\) diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-1.B-1.d b/ld/testsuite/ld-ctf/conflicting-cycle-1.B-1.d index 2ed3ce1..2b75e6b 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-1.B-1.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-1.B-1.d @@ -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 diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-1.B-2.d b/ld/testsuite/ld-ctf/conflicting-cycle-1.B-2.d index 3b9b7f6..c86e871 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-1.B-2.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-1.B-2.d @@ -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 diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d b/ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d index 83c56fe..7296272 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-1.parent.d @@ -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: .* diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-2.A-1.d b/ld/testsuite/ld-ctf/conflicting-cycle-2.A-1.d index 6a07d36..770ef99 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-2.A-1.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-2.A-1.d @@ -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 diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-2.A-2.d b/ld/testsuite/ld-ctf/conflicting-cycle-2.A-2.d index 6775421..d71c5ba 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-2.A-2.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-2.A-2.d @@ -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 diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-2.parent.d b/ld/testsuite/ld-ctf/conflicting-cycle-2.parent.d index 30be9b0..f7427e3 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-2.parent.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-2.parent.d @@ -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\) diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-3.C-1.d b/ld/testsuite/ld-ctf/conflicting-cycle-3.C-1.d index b60768f..6f42a49 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-3.C-1.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-3.C-1.d @@ -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 diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-3.C-2.d b/ld/testsuite/ld-ctf/conflicting-cycle-3.C-2.d index 590d373..55d9db6 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-3.C-2.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-3.C-2.d @@ -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 diff --git a/ld/testsuite/ld-ctf/conflicting-cycle-3.parent.d b/ld/testsuite/ld-ctf/conflicting-cycle-3.parent.d index dbe2e46..e63e051 100644 --- a/ld/testsuite/ld-ctf/conflicting-cycle-3.parent.d +++ b/ld/testsuite/ld-ctf/conflicting-cycle-3.parent.d @@ -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: .* diff --git a/ld/testsuite/ld-ctf/conflicting-enums.d b/ld/testsuite/ld-ctf/conflicting-enums.d index 4f8cf81..b334859 100644 --- a/ld/testsuite/ld-ctf/conflicting-enums.d +++ b/ld/testsuite/ld-ctf/conflicting-enums.d @@ -11,7 +11,7 @@ Contents of CTF section .ctf: Header: Magic number: 0xdff2 - Version: 4 \(CTF_VERSION_3\) + Version: 5 \(CTF_VERSION_4\) #... Types: #... diff --git a/ld/testsuite/ld-ctf/conflicting-typedefs.d b/ld/testsuite/ld-ctf/conflicting-typedefs.d index beb1f77..4610963 100644 --- a/ld/testsuite/ld-ctf/conflicting-typedefs.d +++ b/ld/testsuite/ld-ctf/conflicting-typedefs.d @@ -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 .* diff --git a/ld/testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d b/ld/testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d index c83789a..a2018e9 100644 --- a/ld/testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d +++ b/ld/testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d @@ -15,7 +15,7 @@ Contents of CTF section .ctf: Header: Magic number: 0xdff2 - Version: 4 \(CTF_VERSION_3\) + Version: 5 \(CTF_VERSION_4\) #... Labels: diff --git a/ld/testsuite/ld-ctf/cross-tu-into-cycle.d b/ld/testsuite/ld-ctf/cross-tu-into-cycle.d index 903dedb..ec404a4 100644 --- a/ld/testsuite/ld-ctf/cross-tu-into-cycle.d +++ b/ld/testsuite/ld-ctf/cross-tu-into-cycle.d @@ -17,7 +17,7 @@ Contents of CTF section .ctf: Header: Magic number: 0xdff2 - Version: 4 \(CTF_VERSION_3\) + Version: 5 \(CTF_VERSION_4\) #... Labels: diff --git a/ld/testsuite/ld-ctf/cross-tu-noncyclic.d b/ld/testsuite/ld-ctf/cross-tu-noncyclic.d index 28c2eb4..7e7895b 100644 --- a/ld/testsuite/ld-ctf/cross-tu-noncyclic.d +++ b/ld/testsuite/ld-ctf/cross-tu-noncyclic.d @@ -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: .* diff --git a/ld/testsuite/ld-ctf/cycle-1.d b/ld/testsuite/ld-ctf/cycle-1.d index 379f12f..c01d369 100644 --- a/ld/testsuite/ld-ctf/cycle-1.d +++ b/ld/testsuite/ld-ctf/cycle-1.d @@ -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: .* diff --git a/ld/testsuite/ld-ctf/cycle-2.A.d b/ld/testsuite/ld-ctf/cycle-2.A.d index ab3876c..c3f17bd 100644 --- a/ld/testsuite/ld-ctf/cycle-2.A.d +++ b/ld/testsuite/ld-ctf/cycle-2.A.d @@ -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: .* diff --git a/ld/testsuite/ld-ctf/cycle-2.B.d b/ld/testsuite/ld-ctf/cycle-2.B.d index 65d702e..92315b3 100644 --- a/ld/testsuite/ld-ctf/cycle-2.B.d +++ b/ld/testsuite/ld-ctf/cycle-2.B.d @@ -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: .* diff --git a/ld/testsuite/ld-ctf/cycle-2.C.d b/ld/testsuite/ld-ctf/cycle-2.C.d index 81aa6dd..f37e3f3 100644 --- a/ld/testsuite/ld-ctf/cycle-2.C.d +++ b/ld/testsuite/ld-ctf/cycle-2.C.d @@ -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: .* diff --git a/ld/testsuite/ld-ctf/data-func-conflicted-vars.d b/ld/testsuite/ld-ctf/data-func-conflicted-vars.d index 4e570c6..f10fa98 100644 --- a/ld/testsuite/ld-ctf/data-func-conflicted-vars.d +++ b/ld/testsuite/ld-ctf/data-func-conflicted-vars.d @@ -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 diff --git a/ld/testsuite/ld-ctf/data-func-conflicted.d b/ld/testsuite/ld-ctf/data-func-conflicted.d index b0db511..71f6edb 100644 --- a/ld/testsuite/ld-ctf/data-func-conflicted.d +++ b/ld/testsuite/ld-ctf/data-func-conflicted.d @@ -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 diff --git a/ld/testsuite/ld-ctf/diag-cttname-null.d b/ld/testsuite/ld-ctf/diag-cttname-null.d index 511908e..73933f2 100644 --- a/ld/testsuite/ld-ctf/diag-cttname-null.d +++ b/ld/testsuite/ld-ctf/diag-cttname-null.d @@ -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]*\) diff --git a/ld/testsuite/ld-ctf/diag-cuname.d b/ld/testsuite/ld-ctf/diag-cuname.d index d858b5f..a2089c6 100644 --- a/ld/testsuite/ld-ctf/diag-cuname.d +++ b/ld/testsuite/ld-ctf/diag-cuname.d @@ -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: \(\?\) #... diff --git a/ld/testsuite/ld-ctf/diag-parlabel.d b/ld/testsuite/ld-ctf/diag-parlabel.d index 892970b..f69f48c 100644 --- a/ld/testsuite/ld-ctf/diag-parlabel.d +++ b/ld/testsuite/ld-ctf/diag-parlabel.d @@ -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\) diff --git a/ld/testsuite/ld-ctf/diag-wrong-magic-number-mixed.d b/ld/testsuite/ld-ctf/diag-wrong-magic-number-mixed.d index 668fa15..26c3412 100644 --- a/ld/testsuite/ld-ctf/diag-wrong-magic-number-mixed.d +++ b/ld/testsuite/ld-ctf/diag-wrong-magic-number-mixed.d @@ -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\) diff --git a/ld/testsuite/ld-ctf/enum-forward.d b/ld/testsuite/ld-ctf/enum-forward.d index c53364e..e26f18a 100644 --- a/ld/testsuite/ld-ctf/enum-forward.d +++ b/ld/testsuite/ld-ctf/enum-forward.d @@ -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\) #... diff --git a/ld/testsuite/ld-ctf/enums.d b/ld/testsuite/ld-ctf/enums.d index 501c18f..acc1bfc 100644 --- a/ld/testsuite/ld-ctf/enums.d +++ b/ld/testsuite/ld-ctf/enums.d @@ -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 #... diff --git a/ld/testsuite/ld-ctf/forward.d b/ld/testsuite/ld-ctf/forward.d index 5998ecb..51412a4 100644 --- a/ld/testsuite/ld-ctf/forward.d +++ b/ld/testsuite/ld-ctf/forward.d @@ -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\) #... diff --git a/ld/testsuite/ld-ctf/function.d b/ld/testsuite/ld-ctf/function.d index 66c67eb..971b021 100644 --- a/ld/testsuite/ld-ctf/function.d +++ b/ld/testsuite/ld-ctf/function.d @@ -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\) diff --git a/ld/testsuite/ld-ctf/nonrepresentable-member.d b/ld/testsuite/ld-ctf/nonrepresentable-member.d index 6c76253..b683b48 100644 --- a/ld/testsuite/ld-ctf/nonrepresentable-member.d +++ b/ld/testsuite/ld-ctf/nonrepresentable-member.d @@ -10,7 +10,7 @@ Contents of CTF section .ctf: Header: Magic number: 0xdff2 - Version: 4 \(CTF_VERSION_3\) + Version: 5 \(CTF_VERSION_4\) #... Types: #... diff --git a/ld/testsuite/ld-ctf/nonrepresentable.d b/ld/testsuite/ld-ctf/nonrepresentable.d index f02f52c..10fe830 100644 --- a/ld/testsuite/ld-ctf/nonrepresentable.d +++ b/ld/testsuite/ld-ctf/nonrepresentable.d @@ -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: #... diff --git a/ld/testsuite/ld-ctf/overlapping-enums-2.d b/ld/testsuite/ld-ctf/overlapping-enums-2.d index 1adfd86..cf702e1 100644 --- a/ld/testsuite/ld-ctf/overlapping-enums-2.d +++ b/ld/testsuite/ld-ctf/overlapping-enums-2.d @@ -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]*\) diff --git a/ld/testsuite/ld-ctf/overlapping-enums.d b/ld/testsuite/ld-ctf/overlapping-enums.d index 7cf57d6..a2e435a 100644 --- a/ld/testsuite/ld-ctf/overlapping-enums.d +++ b/ld/testsuite/ld-ctf/overlapping-enums.d @@ -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]*\) diff --git a/ld/testsuite/ld-ctf/slice.d b/ld/testsuite/ld-ctf/slice.d index 838607f..5567cca 100644 --- a/ld/testsuite/ld-ctf/slice.d +++ b/ld/testsuite/ld-ctf/slice.d @@ -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 #... diff --git a/ld/testsuite/ld-ctf/super-sub-cycles.d b/ld/testsuite/ld-ctf/super-sub-cycles.d index 4eb009d..ccac9a1 100644 --- a/ld/testsuite/ld-ctf/super-sub-cycles.d +++ b/ld/testsuite/ld-ctf/super-sub-cycles.d @@ -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 #... diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c index a37d4b7..8b65581 100644 --- a/libctf/ctf-dump.c +++ b/libctf/ctf-dump.c @@ -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; diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index 6373ecb..5faac65 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -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); diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index 942a53a..a7aa46e 100644 --- a/libctf/ctf-open.c +++ b/libctf/ctf-open.c @@ -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) diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c index 9efdb16..a14514c 100644 --- a/libctf/ctf-serialize.c +++ b/libctf/ctf-serialize.c @@ -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 |