Skip to content

Commit 22f9ff1

Browse files
committed
Improve build ID deduction for modules
1 parent cd238a4 commit 22f9ff1

File tree

6 files changed

+199
-82
lines changed

6 files changed

+199
-82
lines changed

include/deemon/dec.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ struct Dee_dec_deptab {
409409
(void)((self)->ddpt_depv = NULL, (self)->ddpt_depc = (self)->ddpt_depa = 0)
410410

411411
struct Dee_dec_ptrtab_entry {
412-
void const *dpte_ptr; /* [1..1] Source address that was already encoded */
413-
size_t dote_off; /* Offset from `dw_base' to where "dpte_ptr" was written */
414-
size_t dote_siz; /* # of bytes associated with "dpte_ptr" */
412+
void const *dpte_ptr; /* [1..1] Source address that was already encoded */
413+
Dee_seraddr_t dote_off; /* Offset from `dw_base' to where "dpte_ptr" was written */
414+
size_t dote_siz; /* # of bytes associated with "dpte_ptr" */
415415
};
416416
#define Dee_dec_ptrtab_entry_getminaddr(self) ((__BYTE_TYPE__ *)(self)->dpte_ptr)
417417
#define Dee_dec_ptrtab_entry_getmaxaddr(self) ((__BYTE_TYPE__ *)(self)->dpte_ptr + (self)->dote_siz - 1)
@@ -450,16 +450,16 @@ typedef struct Dee_dec_writer {
450450
__BYTE_TYPE__ *dw_base; /* [1..1][owned] Base address of memory block of dec file being built */
451451
#endif /* !DEE_SOURCE */
452452
size_t dw_alloc; /* Allocated buffer size for `dw_base' */
453-
size_t dw_used; /* [<= dw_alloc] Used buffer size for `dw_base' */
453+
Dee_seraddr_t dw_used; /* [<= dw_alloc] Used buffer size for `dw_base' */
454454
size_t dw_hlast; /* Chunk size during the previous call to `DeeDecWriter_Malloc()' */
455455
struct Dee_dec_reltab dw_srel; /* Table of self-relocations */
456456
struct Dee_dec_reltab dw_drel; /* Table of relocations against deemon-core objects */
457457
struct Dee_dec_rreltab dw_drrel; /* Table of incref-relocations against deemon-core objects (increfs already happened here) */
458458
struct Dee_dec_rrelatab dw_drrela; /* Table of incref-relocations against deemon-core objects (increfs already happened here) */
459459
struct Dee_dec_deptab dw_deps; /* Table of dependent modules */
460460
struct Dee_dec_fdeptab dw_fdeps; /* Table of dependent files */
461-
size_t dw_gchead; /* [0..1] Offset to first `struct gc_head_link' (tracking for these objects must begin after relocations were done) */
462-
size_t dw_gctail; /* [0..1] Offset to last `struct gc_head_link' (links between these objects were already established via `dw_srel') */
461+
Dee_seraddr_t dw_gchead; /* [0..1] Offset to first `struct gc_head_link' (tracking for these objects must begin after relocations were done) */
462+
Dee_seraddr_t dw_gctail; /* [0..1] Offset to last `struct gc_head_link' (links between these objects were already established via `dw_srel') */
463463
struct Dee_dec_ptrtab dw_known; /* Table of known, already-encoded pointers */
464464
unsigned int dw_flags; /* Dec writer flags (set of `DeeDecWriter_F_*') */
465465
} DeeDecWriter;
@@ -552,8 +552,8 @@ DeeDecWriter_AddFileDep(DeeDecWriter *__restrict self,
552552
* `DeeModuleObject' describing the dec file itself).
553553
* NOTE: Can only be used when `self->e_type == Dee_DEC_TYPE_RELOC'
554554
*
555-
* On success, `self' is inherited by `return', such that rather than
556-
* calling `DeeDec_Ehdr_Destroy(self)', you must `(return)'
555+
* On success, `self' is inherited by `return', such that rather than calling
556+
* `DeeDec_Ehdr_Destroy(self)', you must `DeeDec_DestroyUntracked(return)'
557557
*
558558
* @param: flags: Set of `0 | DeeModule_IMPORT_F_CTXDIR':
559559
* - DeeModule_IMPORT_F_CTXDIR: When set, "context_absname...+=context_absname_size" is

include/deemon/dex.h

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,24 @@ struct Dee_dex_symbol {
8686
__UINTPTR_HALF_TYPE__ _ds_index; /* Used internally during initialization */
8787
};
8888

89+
union Dee_module_buildid;
8990
struct Dee_module_dexinfo;
9091
struct Dee_module_dexdata {
91-
struct Dee_module_object *mdx_module; /* [1..1][const] Associated dex module descriptor */
92-
struct Dee_dex_symbol const *mdx_export; /* [1..mdx_module->mo_globalc][const] Raw export table of this dex module */
93-
void *mdx_handle; /* [?..?][const][owned] System-specific library handle (filled in during loading) */
94-
struct Dee_module_dexinfo *mdx_info; /* [0..1][const] Used internally. Initialize to "NULL" in dex modules */
92+
struct Dee_module_object *mdx_module; /* [1..1][const] Associated DEX module descriptor */
93+
struct Dee_dex_symbol const *mdx_export; /* [1..mdx_module->mo_globalc][const] Raw export table of this DEX module */
94+
union Dee_module_buildid const *mdx_buildid; /* [0..1][const] 16-byte Build ID of the DEX module (if available) -- set to
95+
* "ADDR(.note.gnu.build-id) + 16" if available, or to 16 random bytes if
96+
* that is possible */
9597

9698
/* [0..1][const] Optional initializer/finalizer/clear callbacks. */
9799
WUNUSED_T int (DCALL *mdx_init)(void);
98100
void (DCALL *mdx_fini)(void);
99101
bool (DCALL *mdx_clear)(void);
100102

101-
void *_mdx_pad[9]; /* For future expansion (must be 0-initialized by dex modules) */
103+
/* Internal fields... */
104+
void *mdx_handle; /* [?..?][const][owned] System-specific library handle (filled in during loading) */
105+
struct Dee_module_dexinfo *mdx_info; /* [0..1][const] Used internally. Initialize to "NULL" in DEX modules */
106+
void *_mdx_pad[8]; /* For future expansion (must be 0-initialized by DEX modules) */
102107
};
103108

104109
#if defined(CONFIG_BUILDING_DEEMON) || defined(CONFIG_BUILDING_DEX)
@@ -146,7 +151,7 @@ INTDEF __BYTE_TYPE__ _end[];
146151
#define Dee_DEX_END(init, fini, clear) \
147152
}; \
148153
STATIC_ASSERT_MSG(COMPILER_LENOF(_dex_symbols) > 0, \
149-
"A dex module must have at least 1 export"); \
154+
"A DEX module must have at least 1 export"); \
150155
enum { _DEX_BUCKETM = __Dee_NEXT_POWER_OF_2_16(COMPILER_LENOF(_dex_symbols) + 1) - 1 }; \
151156
PRIVATE struct Dee_module_symbol _dex_bucketv[_DEX_BUCKETM + 1] = {}; \
152157
Dee_MODULE_STRUCT(_dex_object_raw, COMPILER_LENOF(_dex_symbols)); \
@@ -156,15 +161,15 @@ INTDEF __BYTE_TYPE__ _end[];
156161
}; \
157162
EXPDEF struct _dex_object DEX; \
158163
PRIVATE struct Dee_module_dexdata _dex_data = { \
159-
/* .mdx_module = */ (struct Dee_module_object *)&DEX.m_dex, \
160-
/* .mdx_export = */ _dex_symbols, \
161-
/* .mdx_handle = */ NULL, /* Init doesn't matter */ \
162-
/* .mdx_info = */ NULL, \
163-
/* .mdx_init = */ init, \
164-
/* .mdx_fini = */ fini, \
165-
/* .mdx_clear = */ clear, \
166-
/* ._mdx_pad = */ { NULL, NULL, NULL, NULL, NULL, \
167-
NULL, NULL, NULL, NULL } \
164+
/* .mdx_module = */ (struct Dee_module_object *)&DEX.m_dex, \
165+
/* .mdx_export = */ _dex_symbols, \
166+
/* .mdx_buildid = */ NULL, \
167+
/* .mdx_init = */ init, \
168+
/* .mdx_fini = */ fini, \
169+
/* .mdx_clear = */ clear, \
170+
/* .mdx_handle = */ NULL, /* Init doesn't matter */ \
171+
/* .mdx_info = */ NULL, \
172+
/* ._mdx_pad = */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } \
168173
}; \
169174
PUBLIC struct _dex_object DEX = {{ _Dee_GC_HEAD_UNTRACKED_INIT }, { \
170175
__Dee_DEX_OBJECT_HEAD_INIT, \
@@ -190,7 +195,7 @@ INTDEF __BYTE_TYPE__ _end[];
190195

191196

192197
#ifdef CONFIG_BUILDING_DEEMON
193-
/* Open loaded system "dex_handle" as a module object. The dex module will have
198+
/* Open loaded system "dex_handle" as a module object. The DEX module will have
194199
* already been hooked into "module_abstree_root", as well as having had its
195200
* "mo_dexdata" fully initialized.
196201
* If the system indicates that "dex_handle" had already been loaded under some
@@ -200,19 +205,19 @@ INTDEF __BYTE_TYPE__ _end[];
200205
*
201206
* @param: absname: The absolute, normalized filesystem name where "dex_handle"
202207
* was loaded from, with its trailing .dll/.so removed (as such,
203-
* this is the name under which a new dex module should appear
208+
* this is the name under which a new DEX module should appear
204209
* within `module_abstree_root')
205210
* @param: dex_handle: The system library handle, as returned by `DeeSystem_DlOpenString()'
206-
* @return: * : The newly loaded dex module.
207-
* @return: NULL: An error was thrown (e.g. "dex_handle" does not refer to a dex module) */
211+
* @return: * : The newly loaded DEX module.
212+
* @return: NULL: An error was thrown (e.g. "dex_handle" does not refer to a DEX module) */
208213
INTDEF WUNUSED NONNULL((1)) DREF DeeModuleObject *DCALL
209214
DeeModule_OpenDex(/*inherit(always)*/ /*utf-8*/ char *__restrict absname,
210215
/*inherit(always)*/ void *dex_handle);
211216

212-
/* Invoke the "mdx_clear" operator on every loaded dex module. */
217+
/* Invoke the "mdx_clear" operator on every loaded DEX module. */
213218
INTDEF bool DCALL DeeModule_ClearDexModuleCaches(void);
214219

215-
/* Unload all loaded dex modules. */
220+
/* Unload all loaded DEX modules. */
216221
INTDEF void DCALL DeeModule_UnloadAllDexModules(void);
217222
#endif /* CONFIG_BUILDING_DEEMON */
218223

include/deemon/module.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,9 @@ DeeModule_GetRootFunction(DeeModuleObject *__restrict self);
972972
* this hash might change, in which case dependents of "self" should also be
973973
* re-build (potentially causing their build IDs to change also).
974974
*
975-
* @return: * : The module's build ID */
976-
DFUNDEF WUNUSED ATTR_RETNONNULL NONNULL((1)) union Dee_module_buildid const *DCALL
975+
* @return: * : The module's build ID
976+
* @return: NULL: An error was thrown */
977+
DFUNDEF WUNUSED NONNULL((1)) union Dee_module_buildid const *DCALL
977978
DeeModule_GetBuildId(DeeModuleObject *__restrict self);
978979

979980
/* Return the directory view of a given module, that is: the (lexicographically

0 commit comments

Comments
 (0)