Commit 7a8ded5a authored by Michael Tremer's avatar Michael Tremer

Merge branch 'apple'

parents 191830da 1d9cd868
...@@ -6,6 +6,8 @@ AM_MAKEFLAGS = --no-print-directory ...@@ -6,6 +6,8 @@ AM_MAKEFLAGS = --no-print-directory
SUBDIRS = . po SUBDIRS = . po
BINDINGS = BINDINGS =
OS = $(shell uname -s)
if ENABLE_PERL if ENABLE_PERL
BINDINGS += perl BINDINGS += perl
endif endif
...@@ -19,9 +21,16 @@ AM_CFLAGS = ${my_CFLAGS} \ ...@@ -19,9 +21,16 @@ AM_CFLAGS = ${my_CFLAGS} \
-ffunction-sections \ -ffunction-sections \
-fdata-sections -fdata-sections
AM_LDFLAGS = \ AM_LDFLAGS =
-Wl,--gc-sections \
-Wl,--as-needed # leaving a space here to work around automake's conditionals
ifeq ($(OS),Darwin)
AM_LDFLAGS += -Wl,-dead_strip
else
AM_LDFLAGS += \
-Wl,--as-needed \
-Wl,--gc-sections
endif
LIBLOC_CURRENT=0 LIBLOC_CURRENT=0
LIBLOC_REVISION=0 LIBLOC_REVISION=0
...@@ -68,6 +77,7 @@ EXTRA_DIST += \ ...@@ -68,6 +77,7 @@ EXTRA_DIST += \
pkginclude_HEADERS = \ pkginclude_HEADERS = \
src/loc/libloc.h \ src/loc/libloc.h \
src/loc/as.h \ src/loc/as.h \
src/loc/compat.h \
src/loc/country.h \ src/loc/country.h \
src/loc/database.h \ src/loc/database.h \
src/loc/format.h \ src/loc/format.h \
...@@ -97,8 +107,13 @@ src_libloc_la_CFLAGS = \ ...@@ -97,8 +107,13 @@ src_libloc_la_CFLAGS = \
src_libloc_la_LDFLAGS = \ src_libloc_la_LDFLAGS = \
$(AM_LDFLAGS) \ $(AM_LDFLAGS) \
-version-info $(LIBLOC_CURRENT):$(LIBLOC_REVISION):$(LIBLOC_AGE) \ -version-info $(LIBLOC_CURRENT):$(LIBLOC_REVISION):$(LIBLOC_AGE)
-Wl,--version-script=$(top_srcdir)/src/libloc.sym
if HAVE_LD_VERSION_SCRIPT
src_libloc_la_LDFLAGS += -Wl,--version-script=$(top_srcdir)/src/libloc.sym
else
src_libloc_la_LDFLAGS += -export-symbols $(top_srcdir)/src/libloc.sym
endif
src_libloc_la_DEPENDENCIES = \ src_libloc_la_DEPENDENCIES = \
${top_srcdir}/src/libloc.sym ${top_srcdir}/src/libloc.sym
......
...@@ -28,6 +28,7 @@ LT_INIT([ ...@@ -28,6 +28,7 @@ LT_INIT([
pic-only pic-only
]) ])
AC_PREFIX_DEFAULT([/usr]) AC_PREFIX_DEFAULT([/usr])
gl_LD_VERSION_SCRIPT
IT_PROG_INTLTOOL([0.40.0]) IT_PROG_INTLTOOL([0.40.0])
GETTEXT_PACKAGE=${PACKAGE_TARNAME} GETTEXT_PACKAGE=${PACKAGE_TARNAME}
......
# ld-version-script.m4 serial 4
dnl Copyright (C) 2008-2015 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Simon Josefsson
# FIXME: The test below returns a false positive for mingw
# cross-compiles, 'local:' statements does not reduce number of
# exported symbols in a DLL. Use --disable-ld-version-script to work
# around the problem.
# gl_LD_VERSION_SCRIPT
# --------------------
# Check if LD supports linker scripts, and define automake conditional
# HAVE_LD_VERSION_SCRIPT if so.
AC_DEFUN([gl_LD_VERSION_SCRIPT],
[
AC_ARG_ENABLE([ld-version-script],
[AS_HELP_STRING([--enable-ld-version-script],
[enable linker version script (default is enabled when possible)])],
[have_ld_version_script=$enableval],
[AC_CACHE_CHECK([if LD -Wl,--version-script works],
[gl_cv_sys_ld_version_script],
[gl_cv_sys_ld_version_script=no
save_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
echo foo >conftest.map
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
[],
[cat > conftest.map <<EOF
VERS_1 {
global: sym;
};
VERS_2 {
global: sym;
} VERS_1;
EOF
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
[gl_cv_sys_ld_version_script=yes])])
rm -f conftest.map
LDFLAGS=$save_LDFLAGS])
have_ld_version_script=$gl_cv_sys_ld_version_script])
AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT],
[test "$have_ld_version_script" = yes])
])
...@@ -15,14 +15,18 @@ ...@@ -15,14 +15,18 @@
*/ */
#include <ctype.h> #include <ctype.h>
#include <endian.h>
#include <errno.h> #include <errno.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#include <loc/libloc.h> #include <loc/libloc.h>
#include <loc/as.h> #include <loc/as.h>
#include <loc/compat.h>
#include <loc/format.h> #include <loc/format.h>
#include <loc/private.h> #include <loc/private.h>
#include <loc/stringpool.h> #include <loc/stringpool.h>
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <string.h> #include <string.h>
#include <loc/libloc.h> #include <loc/libloc.h>
#include <loc/compat.h>
#include <loc/country.h> #include <loc/country.h>
#include <loc/private.h> #include <loc/private.h>
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ctype.h> #include <ctype.h>
#include <endian.h>
#include <errno.h> #include <errno.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <stddef.h> #include <stddef.h>
...@@ -29,8 +28,13 @@ ...@@ -29,8 +28,13 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#include <loc/libloc.h> #include <loc/libloc.h>
#include <loc/as.h> #include <loc/as.h>
#include <loc/compat.h>
#include <loc/country.h> #include <loc/country.h>
#include <loc/database.h> #include <loc/database.h>
#include <loc/format.h> #include <loc/format.h>
...@@ -132,7 +136,7 @@ static int loc_database_read_as_section_v0(struct loc_database* db, ...@@ -132,7 +136,7 @@ static int loc_database_read_as_section_v0(struct loc_database* db,
off_t as_offset = be32toh(header->as_offset); off_t as_offset = be32toh(header->as_offset);
size_t as_length = be32toh(header->as_length); size_t as_length = be32toh(header->as_length);
DEBUG(db->ctx, "Reading AS section from %jd (%zu bytes)\n", as_offset, as_length); DEBUG(db->ctx, "Reading AS section from %jd (%zu bytes)\n", (intmax_t)as_offset, as_length);
if (as_length > 0) { if (as_length > 0) {
db->as_v0 = mmap(NULL, as_length, PROT_READ, db->as_v0 = mmap(NULL, as_length, PROT_READ,
...@@ -155,7 +159,7 @@ static int loc_database_read_network_nodes_section_v0(struct loc_database* db, ...@@ -155,7 +159,7 @@ static int loc_database_read_network_nodes_section_v0(struct loc_database* db,
size_t network_nodes_length = be32toh(header->network_tree_length); size_t network_nodes_length = be32toh(header->network_tree_length);
DEBUG(db->ctx, "Reading network nodes section from %jd (%zu bytes)\n", DEBUG(db->ctx, "Reading network nodes section from %jd (%zu bytes)\n",
network_nodes_offset, network_nodes_length); (intmax_t)network_nodes_offset, network_nodes_length);
if (network_nodes_length > 0) { if (network_nodes_length > 0) {
db->network_nodes_v0 = mmap(NULL, network_nodes_length, PROT_READ, db->network_nodes_v0 = mmap(NULL, network_nodes_length, PROT_READ,
...@@ -178,7 +182,7 @@ static int loc_database_read_networks_section_v0(struct loc_database* db, ...@@ -178,7 +182,7 @@ static int loc_database_read_networks_section_v0(struct loc_database* db,
size_t networks_length = be32toh(header->network_data_length); size_t networks_length = be32toh(header->network_data_length);
DEBUG(db->ctx, "Reading networks section from %jd (%zu bytes)\n", DEBUG(db->ctx, "Reading networks section from %jd (%zu bytes)\n",
networks_offset, networks_length); (intmax_t)networks_offset, networks_length);
if (networks_length > 0) { if (networks_length > 0) {
db->networks_v0 = mmap(NULL, networks_length, PROT_READ, db->networks_v0 = mmap(NULL, networks_length, PROT_READ,
...@@ -397,7 +401,7 @@ static int loc_database_fetch_as(struct loc_database* db, struct loc_as** as, of ...@@ -397,7 +401,7 @@ static int loc_database_fetch_as(struct loc_database* db, struct loc_as** as, of
if ((size_t)pos >= db->as_count) if ((size_t)pos >= db->as_count)
return -EINVAL; return -EINVAL;
DEBUG(db->ctx, "Fetching AS at position %jd\n", pos); DEBUG(db->ctx, "Fetching AS at position %jd\n", (intmax_t)pos);
int r; int r;
switch (db->version) { switch (db->version) {
...@@ -466,7 +470,7 @@ static int loc_database_fetch_network(struct loc_database* db, struct loc_networ ...@@ -466,7 +470,7 @@ static int loc_database_fetch_network(struct loc_database* db, struct loc_networ
if ((size_t)pos >= db->networks_count) if ((size_t)pos >= db->networks_count)
return -EINVAL; return -EINVAL;
DEBUG(db->ctx, "Fetching network at position %jd\n", pos); DEBUG(db->ctx, "Fetching network at position %jd\n", (intmax_t)pos);
int r; int r;
switch (db->version) { switch (db->version) {
...@@ -497,13 +501,13 @@ static int __loc_database_lookup_handle_leaf(struct loc_database* db, const stru ...@@ -497,13 +501,13 @@ static int __loc_database_lookup_handle_leaf(struct loc_database* db, const stru
const struct loc_database_network_node_v0* node) { const struct loc_database_network_node_v0* node) {
off_t network_index = be32toh(node->network); off_t network_index = be32toh(node->network);
DEBUG(db->ctx, "Handling leaf node at %jd (%jd)\n", node - db->network_nodes_v0, network_index); DEBUG(db->ctx, "Handling leaf node at %jd (%jd)\n", (intmax_t)(node - db->network_nodes_v0), (intmax_t)network_index);
// Fetch the network // Fetch the network
int r = loc_database_fetch_network(db, network, int r = loc_database_fetch_network(db, network,
network_address, prefix, network_index); network_address, prefix, network_index);
if (r) { if (r) {
ERROR(db->ctx, "Could not fetch network %jd from database\n", network_index); ERROR(db->ctx, "Could not fetch network %jd from database\n", (intmax_t)network_index);
return r; return r;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <ctype.h> #include <ctype.h>
#include <loc/libloc.h> #include <loc/libloc.h>
#include <loc/compat.h>
#include <loc/private.h> #include <loc/private.h>
struct loc_ctx { struct loc_ctx {
......
/*
libloc - A library to determine the location of someone on the Internet
Copyright (C) 2019 IPFire Development Team <info@ipfire.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
#ifndef LIBLOC_COMPAT_H
#define LIBLOC_COMPAT_H
#ifdef __APPLE__
/* Hacks to make this library compile on Mac OS X */
#include <libkern/OSByteOrder.h>
#define be16toh(x) OSSwapBigToHostInt16(x)
#define htobe16(x) OSSwapHostToBigInt16(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#ifndef s6_addr16
# define s6_addr16 __u6_addr.__u6_addr16
#endif
#ifndef s6_addr32
# define s6_addr32 __u6_addr.__u6_addr32
#endif
#endif
#endif
...@@ -47,7 +47,7 @@ loc_log_null(struct loc_ctx *ctx, const char *format, ...) {} ...@@ -47,7 +47,7 @@ loc_log_null(struct loc_ctx *ctx, const char *format, ...) {}
# ifdef HAVE___SECURE_GETENV # ifdef HAVE___SECURE_GETENV
# define secure_getenv __secure_getenv # define secure_getenv __secure_getenv
# else # else
# error neither secure_getenv nor __secure_getenv is available # define secure_getenv getenv
# endif # endif
#endif #endif
......
...@@ -16,13 +16,17 @@ ...@@ -16,13 +16,17 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
#include <endian.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#include <loc/libloc.h> #include <loc/libloc.h>
#include <loc/compat.h>
#include <loc/country.h> #include <loc/country.h>
#include <loc/network.h> #include <loc/network.h>
#include <loc/private.h> #include <loc/private.h>
......
use 5.028001;
use ExtUtils::MakeMaker; use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence # See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written. # the contents of the Makefile that is written.
......
...@@ -68,7 +68,7 @@ static int loc_stringpool_mmap(struct loc_stringpool* pool, FILE* f, size_t leng ...@@ -68,7 +68,7 @@ static int loc_stringpool_mmap(struct loc_stringpool* pool, FILE* f, size_t leng
if (pool->mode != STRINGPOOL_MMAP) if (pool->mode != STRINGPOOL_MMAP)
return -EINVAL; return -EINVAL;
DEBUG(pool->ctx, "Reading string pool starting from %zu (%zu bytes)\n", offset, length); DEBUG(pool->ctx, "Reading string pool starting from %jd (%zu bytes)\n", (intmax_t)offset, length);
// Map file content into memory // Map file content into memory
pool->data = pool->pos = mmap(NULL, length, PROT_READ, pool->data = pool->pos = mmap(NULL, length, PROT_READ,
...@@ -236,7 +236,7 @@ static off_t loc_stringpool_append(struct loc_stringpool* pool, const char* stri ...@@ -236,7 +236,7 @@ static off_t loc_stringpool_append(struct loc_stringpool* pool, const char* stri
LOC_EXPORT off_t loc_stringpool_add(struct loc_stringpool* pool, const char* string) { LOC_EXPORT off_t loc_stringpool_add(struct loc_stringpool* pool, const char* string) {
off_t offset = loc_stringpool_find(pool, string); off_t offset = loc_stringpool_find(pool, string);
if (offset >= 0) { if (offset >= 0) {
DEBUG(pool->ctx, "Found '%s' at position %jd\n", string, offset); DEBUG(pool->ctx, "Found '%s' at position %jd\n", string, (intmax_t)offset);
return offset; return offset;
} }
...@@ -251,7 +251,7 @@ LOC_EXPORT void loc_stringpool_dump(struct loc_stringpool* pool) { ...@@ -251,7 +251,7 @@ LOC_EXPORT void loc_stringpool_dump(struct loc_stringpool* pool) {
if (!string) if (!string)
break; break;
printf("%jd (%zu): %s\n", offset, strlen(string), string); printf("%jd (%zu): %s\n", (intmax_t)offset, strlen(string), string);
offset = loc_stringpool_get_next_offset(pool, offset); offset = loc_stringpool_get_next_offset(pool, offset);
} }
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
Lesser General Public License for more details. Lesser General Public License for more details.
*/ */
#include <endian.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -22,8 +21,13 @@ ...@@ -22,8 +21,13 @@
#include <sys/queue.h> #include <sys/queue.h>
#include <time.h> #include <time.h>
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#include <loc/libloc.h> #include <loc/libloc.h>
#include <loc/as.h> #include <loc/as.h>
#include <loc/compat.h>
#include <loc/country.h> #include <loc/country.h>
#include <loc/format.h> #include <loc/format.h>
#include <loc/network.h> #include <loc/network.h>
...@@ -231,7 +235,7 @@ static void align_page_boundary(off_t* offset, FILE* f) { ...@@ -231,7 +235,7 @@ static void align_page_boundary(off_t* offset, FILE* f) {
static int loc_database_write_pool(struct loc_writer* writer, static int loc_database_write_pool(struct loc_writer* writer,
struct loc_database_header_v0* header, off_t* offset, FILE* f) { struct loc_database_header_v0* header, off_t* offset, FILE* f) {
// Save the offset of the pool section // Save the offset of the pool section
DEBUG(writer->ctx, "Pool starts at %jd bytes\n", *offset); DEBUG(writer->ctx, "Pool starts at %jd bytes\n", (intmax_t)*offset);
header->pool_offset = htobe32(*offset); header->pool_offset = htobe32(*offset);
// Write the pool // Write the pool
...@@ -246,7 +250,7 @@ static int loc_database_write_pool(struct loc_writer* writer, ...@@ -246,7 +250,7 @@ static int loc_database_write_pool(struct loc_writer* writer,
static int loc_database_write_as_section(struct loc_writer* writer, static int loc_database_write_as_section(struct loc_writer* writer,
struct loc_database_header_v0* header, off_t* offset, FILE* f) { struct loc_database_header_v0* header, off_t* offset, FILE* f) {
DEBUG(writer->ctx, "AS section starts at %jd bytes\n", *offset); DEBUG(writer->ctx, "AS section starts at %jd bytes\n", (intmax_t)*offset);
header->as_offset = htobe32(*offset); header->as_offset = htobe32(*offset);
size_t as_length = 0; size_t as_length = 0;
...@@ -321,7 +325,7 @@ static void free_network(struct network* network) { ...@@ -321,7 +325,7 @@ static void free_network(struct network* network) {
static int loc_database_write_networks(struct loc_writer* writer, static int loc_database_write_networks(struct loc_writer* writer,
struct loc_database_header_v0* header, off_t* offset, FILE* f) { struct loc_database_header_v0* header, off_t* offset, FILE* f) {
// Write the network tree // Write the network tree
DEBUG(writer->ctx, "Network tree starts at %jd bytes\n", *offset); DEBUG(writer->ctx, "Network tree starts at %jd bytes\n", (intmax_t)*offset);
header->network_tree_offset = htobe32(*offset); header->network_tree_offset = htobe32(*offset);
size_t network_tree_length = 0; size_t network_tree_length = 0;
...@@ -411,7 +415,7 @@ static int loc_database_write_networks(struct loc_writer* writer, ...@@ -411,7 +415,7 @@ static int loc_database_write_networks(struct loc_writer* writer,
align_page_boundary(offset, f); align_page_boundary(offset, f);
DEBUG(writer->ctx, "Networks data section starts at %jd bytes\n", *offset); DEBUG(writer->ctx, "Networks data section starts at %jd bytes\n", (intmax_t)*offset);
header->network_data_offset = htobe32(*offset); header->network_data_offset = htobe32(*offset);
// We have now written the entire tree and have all networks // We have now written the entire tree and have all networks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment