llvm/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c

/*===- InstrProfilingPlatformLinux.c - Profile data Linux platform ------===*\
|*
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|* See https://llvm.org/LICENSE.txt for license information.
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|*
\*===----------------------------------------------------------------------===*/

#if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
    (defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) || \
    defined(_AIX)

#if !defined(_AIX)
#include <elf.h>
#include <link.h>
#endif
#include <stdlib.h>
#include <string.h>

#include "InstrProfiling.h"
#include "InstrProfilingInternal.h"

#define PROF_DATA_START
#define PROF_DATA_STOP
#define PROF_NAME_START
#define PROF_NAME_STOP
#define PROF_VNAME_START
#define PROF_VNAME_STOP
#define PROF_CNTS_START
#define PROF_CNTS_STOP
#define PROF_VTABLE_START
#define PROF_VTABLE_STOP
#define PROF_BITS_START
#define PROF_BITS_STOP
#define PROF_ORDERFILE_START
#define PROF_VNODES_START
#define PROF_VNODES_STOP

/* Declare section start and stop symbols for various sections
 * generated by compiler instrumentation.
 */
extern __llvm_profile_data PROF_DATA_START COMPILER_RT_VISIBILITY
    COMPILER_RT_WEAK;
extern __llvm_profile_data PROF_DATA_STOP COMPILER_RT_VISIBILITY
    COMPILER_RT_WEAK;
extern char PROF_CNTS_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern char PROF_CNTS_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern VTableProfData PROF_VTABLE_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern VTableProfData PROF_VTABLE_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern char PROF_VNAME_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern char PROF_VNAME_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern char PROF_BITS_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern char PROF_BITS_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern uint32_t PROF_ORDERFILE_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern char PROF_NAME_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern char PROF_NAME_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern ValueProfNode PROF_VNODES_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
extern ValueProfNode PROF_VNODES_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;

COMPILER_RT_VISIBILITY const __llvm_profile_data *
__llvm_profile_begin_data(void) {}
COMPILER_RT_VISIBILITY const __llvm_profile_data *
__llvm_profile_end_data(void) {}
COMPILER_RT_VISIBILITY const char *__llvm_profile_begin_names(void) {}
COMPILER_RT_VISIBILITY const char *__llvm_profile_end_names(void) {}
COMPILER_RT_VISIBILITY const char *__llvm_profile_begin_vtabnames(void) {}
COMPILER_RT_VISIBILITY const char *__llvm_profile_end_vtabnames(void) {}
COMPILER_RT_VISIBILITY const VTableProfData *
__llvm_profile_begin_vtables(void) {}
COMPILER_RT_VISIBILITY const VTableProfData *__llvm_profile_end_vtables(void) {}
COMPILER_RT_VISIBILITY char *__llvm_profile_begin_counters(void) {}
COMPILER_RT_VISIBILITY char *__llvm_profile_end_counters(void) {}
COMPILER_RT_VISIBILITY char *__llvm_profile_begin_bitmap(void) {}
COMPILER_RT_VISIBILITY char *__llvm_profile_end_bitmap(void) {}
COMPILER_RT_VISIBILITY uint32_t *__llvm_profile_begin_orderfile(void) {}

COMPILER_RT_VISIBILITY ValueProfNode *
__llvm_profile_begin_vnodes(void) {}
COMPILER_RT_VISIBILITY ValueProfNode *__llvm_profile_end_vnodes(void) {}
COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode =;
COMPILER_RT_VISIBILITY ValueProfNode *EndVNode =;

#ifdef NT_GNU_BUILD_ID
static size_t RoundUp(size_t size, size_t align) {}

/*
 * Look for the note that has the name "GNU\0" and type NT_GNU_BUILD_ID
 * that contains build id. If build id exists, write binary id.
 *
 * Each note in notes section starts with a struct which includes
 * n_namesz, n_descsz, and n_type members. It is followed by the name
 * (whose length is defined in n_namesz) and then by the descriptor
 * (whose length is defined in n_descsz).
 *
 * Note sections like .note.ABI-tag and .note.gnu.build-id are aligned
 * to 4 bytes, so round n_namesz and n_descsz to the nearest 4 bytes.
 */
static int WriteBinaryIdForNote(ProfDataWriter *Writer,
                                const ElfW(Nhdr) * Note) {}

/*
 * Helper function that iterates through notes section and find build ids.
 * If writer is given, write binary ids into profiles.
 * If an error happens while writing, return -1.
 */
static int WriteBinaryIds(ProfDataWriter *Writer, const ElfW(Nhdr) * Note,
                          const ElfW(Nhdr) * NotesEnd) {}

/*
 * Write binary ids into profiles if writer is given.
 * Return the total size of binary ids.
 * If an error happens while writing, return -1.
 */
COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {}
#elif !defined(_AIX) /* !NT_GNU_BUILD_ID */
/*
 * Fallback implementation for targets that don't support the GNU
 * extensions NT_GNU_BUILD_ID and __ehdr_start.
 */
COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
  return 0;
}
#endif

#endif