Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d753faa authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

liblog: audit declare LIBLOG_ABI_PUBLIC

(cherry pick from commit be1d3c21)

- replace <sys/cdefs.h> with local "log_cdefs.h" which
  fortifies and expands definitions, adding LIBLOG_ABI_PUBLIC,
  LIBLOG_HIDDEN, LIBLOG_ABI_PRIVATE and LIBLOG_WEAK.
- clearly tag each interface as LIBLOG_ABI_PUBLIC, LIBLOG_HIDDEN,
  LIBLOG_ABI_PRIVATE, LIBLOG_WEAK or static depending on scope
- Add -fvisibility=hidden to ensure nothing else leaks
- some code standard adjustments

Bug: 27566046
Change-Id: Ic14033c4e6d833d973beb035ddc1c6134fb35a3f
parent 029c7373
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ LOCAL_SRC_FILES := $(liblog_host_sources)
LOCAL_SRC_FILES_darwin := event_tag_map.c
LOCAL_SRC_FILES_darwin := event_tag_map.c
LOCAL_SRC_FILES_linux := event_tag_map.c
LOCAL_SRC_FILES_linux := event_tag_map.c
LOCAL_SRC_FILES_windows := uio.c
LOCAL_SRC_FILES_windows := uio.c
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror $(liblog_cflags)
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror -fvisibility=hidden $(liblog_cflags)
LOCAL_MULTILIB := both
LOCAL_MULTILIB := both
LOCAL_MODULE_HOST_OS := darwin linux windows
LOCAL_MODULE_HOST_OS := darwin linux windows
include $(BUILD_HOST_STATIC_LIBRARY)
include $(BUILD_HOST_STATIC_LIBRARY)
@@ -59,7 +59,7 @@ include $(BUILD_HOST_SHARED_LIBRARY)
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE := liblog
LOCAL_MODULE := liblog
LOCAL_SRC_FILES := $(liblog_target_sources)
LOCAL_SRC_FILES := $(liblog_target_sources)
LOCAL_CFLAGS := -Werror $(liblog_cflags)
LOCAL_CFLAGS := -Werror -fvisibility=hidden $(liblog_cflags)
# AddressSanitizer runtime library depends on liblog.
# AddressSanitizer runtime library depends on liblog.
LOCAL_SANITIZE := never
LOCAL_SANITIZE := never
include $(BUILD_STATIC_LIBRARY)
include $(BUILD_STATIC_LIBRARY)
@@ -67,7 +67,7 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE := liblog
LOCAL_MODULE := liblog
LOCAL_WHOLE_STATIC_LIBRARIES := liblog
LOCAL_WHOLE_STATIC_LIBRARIES := liblog
LOCAL_CFLAGS := -Werror $(liblog_cflags)
LOCAL_CFLAGS := -Werror -fvisibility=hidden $(liblog_cflags)


# TODO: This is to work around b/24465209. Remove after root cause is fixed
# TODO: This is to work around b/24465209. Remove after root cause is fixed
LOCAL_LDFLAGS_arm := -Wl,--hash-style=both
LOCAL_LDFLAGS_arm := -Wl,--hash-style=both
+6 −3
Original line number Original line Diff line number Diff line
@@ -24,6 +24,8 @@
#include <log/event_tag_map.h>
#include <log/event_tag_map.h>
#include <log/log.h>
#include <log/log.h>


#include "log_cdefs.h"

#define OUT_TAG "EventTagMap"
#define OUT_TAG "EventTagMap"


/*
/*
@@ -61,7 +63,7 @@ static int sortTags(EventTagMap* map);
 * We create a private mapping because we want to terminate the log tag
 * We create a private mapping because we want to terminate the log tag
 * strings with '\0'.
 * strings with '\0'.
 */
 */
EventTagMap* android_openEventTagMap(const char* fileName)
LIBLOG_ABI_PUBLIC EventTagMap* android_openEventTagMap(const char* fileName)
{
{
    EventTagMap* newTagMap;
    EventTagMap* newTagMap;
    off_t end;
    off_t end;
@@ -109,7 +111,7 @@ fail:
/*
/*
 * Close the map.
 * Close the map.
 */
 */
void android_closeEventTagMap(EventTagMap* map)
LIBLOG_ABI_PUBLIC void android_closeEventTagMap(EventTagMap* map)
{
{
    if (map == NULL)
    if (map == NULL)
        return;
        return;
@@ -123,7 +125,8 @@ void android_closeEventTagMap(EventTagMap* map)
 *
 *
 * The entries are sorted by tag number, so we can do a binary search.
 * The entries are sorted by tag number, so we can do a binary search.
 */
 */
const char* android_lookupEventTag(const EventTagMap* map, int tag)
LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map,
                                                     int tag)
{
{
    int hi, lo, mid;
    int hi, lo, mid;


+15 −16
Original line number Original line Diff line number Diff line
@@ -19,23 +19,19 @@
 * passed on to the underlying (fake) log device.  When not in the
 * passed on to the underlying (fake) log device.  When not in the
 * simulator, messages are printed to stderr.
 * simulator, messages are printed to stderr.
 */
 */
#include "fake_log_device.h"

#include <ctype.h>
#include <ctype.h>
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
#if !defined(_WIN32)
#include <pthread.h>
#endif
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>


#include <log/logd.h>
#include <log/logd.h>


#if !defined(_WIN32)
#include "fake_log_device.h"
#include <pthread.h>
#include "log_cdefs.h"
#endif

#ifndef __unused
#define __unused __attribute__((__unused__))
#endif


#define kMaxTagLen  16      /* from the long-dead utils/Log.cpp */
#define kMaxTagLen  16      /* from the long-dead utils/Log.cpp */


@@ -683,7 +679,7 @@ static void setRedirects()
    }
    }
}
}


int fakeLogOpen(const char *pathName, int flags)
LIBLOG_HIDDEN int fakeLogOpen(const char *pathName, int flags)
{
{
    if (redirectOpen == NULL) {
    if (redirectOpen == NULL) {
        setRedirects();
        setRedirects();
@@ -702,19 +698,22 @@ int fakeLogOpen(const char *pathName, int flags)
 * call is in the exit handler. Logging can continue in the exit handler to
 * call is in the exit handler. Logging can continue in the exit handler to
 * help debug HOST tools ...
 * help debug HOST tools ...
 */
 */
int fakeLogClose(int fd)
LIBLOG_HIDDEN int fakeLogClose(int fd)
{
{
    /* Assume that open() was called first. */
    /* Assume that open() was called first. */
    return redirectClose(fd);
    return redirectClose(fd);
}
}


ssize_t fakeLogWritev(int fd, const struct iovec* vector, int count)
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd,
                                    const struct iovec* vector, int count)
{
{
    /* Assume that open() was called first. */
    /* Assume that open() was called first. */
    return redirectWritev(fd, vector, count);
    return redirectWritev(fd, vector, count);
}
}


int __android_log_is_loggable(int prio, const char *tag __unused, int def)
LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio,
                                                const char *tag __unused,
                                                int def)
{
{
    int logLevel = def;
    int logLevel = def;
    return logLevel >= 0 && prio >= logLevel;
    return logLevel >= 0 && prio >= logLevel;
+6 −3
Original line number Original line Diff line number Diff line
@@ -19,10 +19,13 @@


#include <sys/types.h>
#include <sys/types.h>


#include "log_cdefs.h"

struct iovec;
struct iovec;


int fakeLogOpen(const char *pathName, int flags);
LIBLOG_HIDDEN int fakeLogOpen(const char *pathName, int flags);
int fakeLogClose(int fd);
LIBLOG_HIDDEN int fakeLogClose(int fd);
ssize_t fakeLogWritev(int fd, const struct iovec* vector, int count);
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd,
                                    const struct iovec* vector, int count);


#endif // _LIBLOG_FAKE_LOG_DEVICE_H
#endif // _LIBLOG_FAKE_LOG_DEVICE_H

liblog/log_cdefs.h

0 → 100644
+54 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _LIBLOG_CDEFS_H__
#define _LIBLOG_CDEFS_H__

#include <sys/cdefs.h>

/* Declare this library function hidden and internal */
#if defined(_WIN32)
#define LIBLOG_HIDDEN
#else
#define LIBLOG_HIDDEN __attribute__((visibility("hidden")))
#endif

/* Declare this library function visible and external */
#if defined(_WIN32)
#define LIBLOG_ABI_PUBLIC
#else
#define LIBLOG_ABI_PUBLIC __attribute__((visibility("default")))
#endif

/* Declare this library function visible but private */
#define LIBLOG_ABI_PRIVATE LIBLOG_ABI_PUBLIC

/*
 * Declare this library function as reimplementation.
 * Prevent circular dependencies, but allow _real_ library to hijack
 */
#if defined(_WIN32)
#define LIBLOG_WEAK static /* Accept that it is totally private */
#else
#define LIBLOG_WEAK __attribute__((weak,visibility("default")))
#endif

/* Unused argument. For C code only, remove symbol name for C++ */
#ifndef __unused
#define __unused        __attribute__((__unused__))
#endif

#endif /* _LIBLOG_CDEFS_H__ */
Loading