1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

Handle Mach-o object format for UAVOs

Jira OP-921
This commit is contained in:
Philippe Vanhaesendonck 2013-04-24 22:39:39 +02:00
parent 15fd460275
commit b3de04d09f
3 changed files with 32 additions and 1 deletions

View File

@ -34,6 +34,10 @@
#include "openpilot.h"
#include "pios_struct_helper.h"
#if (defined(__MACH__) && defined(__APPLE__))
#include <mach-o/getsect.h>
#endif
// Constants
// Private types
@ -41,9 +45,21 @@
// Macros
#define SET_BITS(var, shift, value, mask) var = (var & ~(mask << shift)) | (value << shift);
/* Table of UAVO handles registered at compile time */
// Mach-o: dummy segment to calculate ASLR offset in sim_osx
#if (defined(__MACH__) && defined(__APPLE__))
static long _aslr_offset __attribute__((section("__DATA,_aslr")));
#endif
/* Table of UAVO handles */
#if (defined(__MACH__) && defined(__APPLE__))
/* Mach-o format */
static struct UAVOData ** __start__uavo_handles;
static struct UAVOData ** __stop__uavo_handles;
#else
/* ELF format: automagically defined at compile time */
extern struct UAVOData * __start__uavo_handles[] __attribute__((weak));
extern struct UAVOData * __stop__uavo_handles[] __attribute__((weak));
#endif
#define UAVO_LIST_ITERATE(_item) \
for (struct UAVOData ** _uavo_slot = __start__uavo_handles; \
@ -199,6 +215,13 @@ int32_t UAVObjInitialize()
// Initialize variables
memset(&stats, 0, sizeof(UAVObjStats));
/* Initialize _uavo_handles start/stop pointers */
#if (defined(__MACH__) && defined(__APPLE__))
uint64_t aslr_offset = (uint64_t) & _aslr_offset - getsectbyname("__DATA","_aslr")->addr;
__start__uavo_handles = (struct UAVOData **) (getsectbyname("__DATA","_uavo_handles")->addr + aslr_offset);
__stop__uavo_handles = (struct UAVOData **) ((uint64_t)__start__uavo_handles + getsectbyname("__DATA","_uavo_handles")->size);
#endif
// Initialize the uavo handle table
memset(__start__uavo_handles, 0,
(uintptr_t)__stop__uavo_handles - (uintptr_t)__start__uavo_handles);

View File

@ -40,7 +40,11 @@
#include "$(NAMELC).h"
// Private variables
#if (defined(__MACH__) && defined(__APPLE__))
static UAVObjHandle handle __attribute__((section("__DATA,_uavo_handles")));
#else
static UAVObjHandle handle __attribute__((section("_uavo_handles")));
#endif
/**
* Initialize object.

View File

@ -55,7 +55,11 @@ struct __attribute__((packed)) fw_version_info {
uint8_t pad[20];
};
#if (defined(__MACH__) && defined(__APPLE__))
const struct fw_version_info fw_version_blob __attribute__((used)) __attribute__((__section__("__TEXT,.fw_version_blob"))) = {
#else
const struct fw_version_info fw_version_blob __attribute__((used)) __attribute__((__section__(".fw_version_blob"))) = {
#endif
.magic = { 'O','p','F','w' },
.commit_hash_prefix = 0x${HASH8},
.timestamp = ${UNIXTIME},