Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion statApp/src/linStat.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,16 @@ template<typename Tbl>
std::shared_ptr<StatTable> tblFactory(const std::string& inst, const Reactor& react) {
return std::make_shared<Tbl>(inst, react);
}

// When adding a new table, make sure to update tblBase.cpp:crossReference()
#define DEFINE_TABLE(name, TblKlass) \
static \
__attribute__((section("linStatTableFactory"), retain, used)) \
const linStat::StatTableFactory tbl ## TblKlass = { \
name, \
&tblFactory<TblKlass>, \
};
}; \
int TblKlass ## _Ref = 0;


struct StatTableIter {
Expand Down
25 changes: 25 additions & 0 deletions statApp/src/tblBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ extern const char __start_linStatTableFactory;
extern const char __stop_linStatTableFactory;
}

#define REF_TABLE(_klass) \
extern int _klass ## _Ref; \
_klass ## _Ref = 1;

// Kludgy attempt to work around object file elimination in static libraries.
static void __attribute__((used))
crossReference() {
REF_TABLE(UptimeTable);
REF_TABLE(HWMonTable);
REF_TABLE(FDTable);
REF_TABLE(NetstatTable);
REF_TABLE(IFStatTable);
REF_TABLE(IRQTable);
REF_TABLE(ProcStatusTable);
REF_TABLE(SysStatTable);
REF_TABLE(PidTable);
REF_TABLE(EthtoolTable);
REF_TABLE(MallInfoTable);
REF_TABLE(StatVFSTable);
REF_TABLE(PDBTable);
REF_TABLE(HostTable);
REF_TABLE(ProcStatTable);
REF_TABLE(MemInfoTable);
}

namespace linStat {

StatTable::~StatTable() {}
Expand Down
Loading