diff options
author | Josh Stone <jistone@redhat.com> | 2015-10-09 10:10:37 -0700 |
---|---|---|
committer | Josh Stone <jistone@redhat.com> | 2015-10-09 10:10:37 -0700 |
commit | 3425454a10d307fae891fb667cf7969e945cde79 (patch) | |
tree | ba30fbaff59ca353f4dad8759770600853fb00c1 /src | |
parent | f17d101232d6d40e192e61441aa02a12ee8cf9b8 (diff) | |
download | elfutils-3425454a10d307fae891fb667cf7969e945cde79.tar.gz |
Trust AC_SYS_LARGEFILE to provide large file support
AC_SYS_LARGEFILE defines _FILE_OFFSET_BITS in config.h if needed for
LFS, and this automatically maps things like open to open64. But quite
a few places used explicit 64-bit names, which won't work on platforms
like FreeBSD where off_t is always 64-bit and there are no foo64 names.
It's better to just trust that AC_SYS_LARGEFILE is doing it correctly.
But we can verify this too, as some file could easily forget to include
config.h. The new tests/run-lfs-symbols.sh checks all build targets
against lfs-symbols (taken from lintian) to make sure everything was
implicitly mapped to 64-bit variants when _FILE_OFFSET_BITS is set.
Signed-off-by: Josh Stone <jistone@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 17 | ||||
-rw-r--r-- | src/elflint.c | 4 | ||||
-rw-r--r-- | src/findtextrel.c | 4 | ||||
-rw-r--r-- | src/ld.c | 2 | ||||
-rw-r--r-- | src/readelf.c | 6 | ||||
-rw-r--r-- | src/strings.c | 68 | ||||
-rw-r--r-- | src/strip.c | 12 | ||||
-rw-r--r-- | src/unstrip.c | 8 |
8 files changed, 69 insertions, 52 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 168bc725..ef09a091 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2015-10-09 Josh Stone <jistone@redhat.com> + + * elflint.c (main): Replace stat64 and fstat64 with stat and fstat. + * readelf.c (process_file): Likewise. + (process_elf_file): Replace off64_t with off_t. + * findtextrel.c (process_file): Replace open64 with open. + * ld.c (main): Replace sizeof (off64_t) with 8. + * strings.c: Replace off64_t with off_t throughout. + (main): Replace stat64 and fstat64 with stat and fstat. + (map_file): Replace mmap64 with mmap. + (read_block): Likewise, and replace lseek64 with lseek. + * strip.c (handle_elf): Replace ftruncate64 with ftruncate. + (process_file): Replace stat64 and fstat64 with stat and fstat. + * unstrip.c (parse_opt): Replace stat64 with stat. + (handle_file): Replace open64 with open. + (open_file): Likewise. + 2015-10-08 Chih-Hung Hsieh <chh@google.com> * ld.c (determine_output_format): Move recursive nested diff --git a/src/elflint.c b/src/elflint.c index c1f0be5e..fac457ea 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -164,9 +164,9 @@ main (int argc, char *argv[]) else { unsigned int prev_error_count = error_count; - struct stat64 st; + struct stat st; - if (fstat64 (fd, &st) != 0) + if (fstat (fd, &st) != 0) { printf ("cannot stat '%s': %m\n", argv[remaining]); close (fd); diff --git a/src/findtextrel.c b/src/findtextrel.c index 0ac6ede2..e78d7b8a 100644 --- a/src/findtextrel.c +++ b/src/findtextrel.c @@ -215,7 +215,7 @@ process_file (const char *fname, bool more_than_one) real_fname = new_fname; } - int fd = open64 (real_fname, O_RDONLY); + int fd = open (real_fname, O_RDONLY); if (fd == -1) { error (0, errno, gettext ("cannot open '%s'"), fname); @@ -388,7 +388,7 @@ cannot get program header index at offset %zd: %s"), fname, fname_len), ".debug"); - fd2 = open64 (difname, O_RDONLY); + fd2 = open (difname, O_RDONLY); if (fd2 != -1 && (elf2 = elf_begin (fd2, ELF_C_READ_MMAP, NULL)) != NULL) dw = dwarf_begin_elf (elf2, DWARF_C_READ, NULL); @@ -277,7 +277,7 @@ main (int argc, char *argv[]) int err; /* Sanity check. We always want to use the LFS functionality. */ - if (sizeof (off_t) != sizeof (off64_t)) + if (sizeof (off_t) != 8) abort (); /* We use no threads here which can interfere with handling a stream. */ diff --git a/src/readelf.c b/src/readelf.c index fe7bc392..5f6e4edd 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -764,8 +764,8 @@ process_file (int fd, const char *fname, bool only_one) dwfl->offline_next_address = 0; if (dwfl_report_offline (dwfl, fname, fname, dwfl_fd) == NULL) { - struct stat64 st; - if (fstat64 (dwfl_fd, &st) != 0) + struct stat st; + if (fstat (dwfl_fd, &st) != 0) error (0, errno, gettext ("cannot stat input file")); else if (unlikely (st.st_size == 0)) error (0, 0, gettext ("input file is empty")); @@ -848,7 +848,7 @@ process_elf_file (Dwfl_Module *dwflmod, int fd) if (ehdr->e_type == ET_REL && print_unrelocated) { /* Read the file afresh. */ - off64_t aroff = elf_getaroff (elf); + off_t aroff = elf_getaroff (elf); pure_elf = elf_begin (fd, ELF_C_READ_MMAP, NULL); if (aroff > 0) { diff --git a/src/strings.c b/src/strings.c index 397ce429..c1d63cd6 100644 --- a/src/strings.c +++ b/src/strings.c @@ -49,8 +49,8 @@ /* Prototypes of local functions. */ -static int read_fd (int fd, const char *fname, off64_t fdlen); -static int read_elf (Elf *elf, int fd, const char *fname, off64_t fdlen); +static int read_fd (int fd, const char *fname, off_t fdlen); +static int read_elf (Elf *elf, int fd, const char *fname, off_t fdlen); /* Name and version of program. */ @@ -138,7 +138,7 @@ static size_t ps; static unsigned char *elfmap; static unsigned char *elfmap_base; static size_t elfmap_size; -static off64_t elfmap_off; +static off_t elfmap_off; int @@ -167,14 +167,14 @@ main (int argc, char *argv[]) /* Determine the page size. We will likely need it a couple of times. */ ps = sysconf (_SC_PAGESIZE); - struct stat64 st; + struct stat st; int result = 0; if (remaining == argc) /* We read from standard input. This we cannot do for a structured file. */ result = read_fd (STDIN_FILENO, print_file_name ? "{standard input}" : NULL, - (fstat64 (STDIN_FILENO, &st) == 0 && S_ISREG (st.st_mode)) + (fstat (STDIN_FILENO, &st) == 0 && S_ISREG (st.st_mode)) ? st.st_size : INT64_C (0x7fffffffffffffff)); else do @@ -189,10 +189,10 @@ main (int argc, char *argv[]) else { const char *fname = print_file_name ? argv[remaining] : NULL; - int fstat_fail = fstat64 (fd, &st); - off64_t fdlen = (fstat_fail + int fstat_fail = fstat (fd, &st); + off_t fdlen = (fstat_fail ? INT64_C (0x7fffffffffffffff) : st.st_size); - if (fdlen > (off64_t) min_len_bytes) + if (fdlen > (off_t) min_len_bytes) { Elf *elf = NULL; if (entire_file @@ -326,7 +326,7 @@ parse_opt (int key, char *arg, static void -process_chunk_mb (const char *fname, const unsigned char *buf, off64_t to, +process_chunk_mb (const char *fname, const unsigned char *buf, off_t to, size_t len, char **unprinted) { size_t curlen = *unprinted == NULL ? 0 : strlen (*unprinted); @@ -403,7 +403,7 @@ process_chunk_mb (const char *fname, const unsigned char *buf, off64_t to, static void -process_chunk (const char *fname, const unsigned char *buf, off64_t to, +process_chunk (const char *fname, const unsigned char *buf, off_t to, size_t len, char **unprinted) { /* We are not going to slow the check down for the 2- and 4-byte @@ -467,7 +467,7 @@ process_chunk (const char *fname, const unsigned char *buf, off64_t to, /* Map a file in as large chunks as possible. */ static void * -map_file (int fd, off64_t start_off, off64_t fdlen, size_t *map_sizep) +map_file (int fd, off_t start_off, off_t fdlen, size_t *map_sizep) { /* Maximum size we mmap. We use an #ifdef to avoid overflows on 32-bit machines. 64-bit machines these days do not have usable @@ -480,7 +480,7 @@ map_file (int fd, off64_t start_off, off64_t fdlen, size_t *map_sizep) # endif /* Try to mmap the file. */ - size_t map_size = MIN ((off64_t) mmap_max, fdlen); + size_t map_size = MIN ((off_t) mmap_max, fdlen); const size_t map_size_min = MAX (MAX (SIZE_MAX / 16, 2 * ps), roundup (2 * min_len_bytes + 1, ps)); void *mem; @@ -489,8 +489,8 @@ map_file (int fd, off64_t start_off, off64_t fdlen, size_t *map_sizep) /* We map the memory for reading only here. Since we will always look at every byte of the file it makes sense to use MAP_POPULATE. */ - mem = mmap64 (NULL, map_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, - fd, start_off); + mem = mmap (NULL, map_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, + fd, start_off); if (mem != MAP_FAILED) { /* We will go through the mapping sequentially. */ @@ -515,7 +515,7 @@ map_file (int fd, off64_t start_off, off64_t fdlen, size_t *map_sizep) /* Read the file without mapping. */ static int -read_block_no_mmap (int fd, const char *fname, off64_t from, off64_t fdlen) +read_block_no_mmap (int fd, const char *fname, off_t from, off_t fdlen) { char *unprinted = NULL; #define CHUNKSIZE 65536 @@ -577,7 +577,7 @@ read_block_no_mmap (int fd, const char *fname, off64_t from, off64_t fdlen) static int -read_block (int fd, const char *fname, off64_t fdlen, off64_t from, off64_t to) +read_block (int fd, const char *fname, off_t fdlen, off_t from, off_t to) { if (elfmap == NULL) { @@ -596,23 +596,23 @@ read_block (int fd, const char *fname, off64_t fdlen, off64_t from, off64_t to) read pointer. */ // XXX Eventually add flag which avoids this if the position // XXX is known to match. - if (from != 0 && lseek64 (fd, from, SEEK_SET) != from) - error (EXIT_FAILURE, errno, gettext ("lseek64 failed")); + if (from != 0 && lseek (fd, from, SEEK_SET) != from) + error (EXIT_FAILURE, errno, gettext ("lseek failed")); return read_block_no_mmap (fd, fname, from, to - from); } - assert ((off64_t) min_len_bytes < fdlen); + assert ((off_t) min_len_bytes < fdlen); - if (to < (off64_t) elfmap_off || from > (off64_t) (elfmap_off + elfmap_size)) + if (to < (off_t) elfmap_off || from > (off_t) (elfmap_off + elfmap_size)) { /* The existing mapping cannot fit at all. Map the new area. We always map the full range of ELFMAP_SIZE bytes even if this extend beyond the end of the file. The Linux kernel handles this OK if the access pages are not touched. */ elfmap_off = from & ~(ps - 1); - if (mmap64 (elfmap, elfmap_size, PROT_READ, - MAP_PRIVATE | MAP_POPULATE | MAP_FIXED, fd, from) + if (mmap (elfmap, elfmap_size, PROT_READ, + MAP_PRIVATE | MAP_POPULATE | MAP_FIXED, fd, from) == MAP_FAILED) error (EXIT_FAILURE, errno, gettext ("re-mmap failed")); elfmap_base = elfmap; @@ -622,23 +622,23 @@ read_block (int fd, const char *fname, off64_t fdlen, off64_t from, off64_t to) /* Use the existing mapping as much as possible. If necessary, map new pages. */ - if (from >= (off64_t) elfmap_off - && from < (off64_t) (elfmap_off + elfmap_size)) + if (from >= (off_t) elfmap_off + && from < (off_t) (elfmap_off + elfmap_size)) /* There are at least a few bytes in this mapping which we can use. */ process_chunk (fname, elfmap_base + (from - elfmap_off), - MIN (to, (off64_t) (elfmap_off + elfmap_size)), - MIN (to, (off64_t) (elfmap_off + elfmap_size)) - from, + MIN (to, (off_t) (elfmap_off + elfmap_size)), + MIN (to, (off_t) (elfmap_off + elfmap_size)) - from, &unprinted); - if (to > (off64_t) (elfmap_off + elfmap_size)) + if (to > (off_t) (elfmap_off + elfmap_size)) { unsigned char *remap_base = elfmap_base; size_t read_now = elfmap_size - (elfmap_base - elfmap); - assert (from >= (off64_t) elfmap_off - && from < (off64_t) (elfmap_off + elfmap_size)); - off64_t handled_to = elfmap_off + elfmap_size; + assert (from >= (off_t) elfmap_off + && from < (off_t) (elfmap_off + elfmap_size)); + off_t handled_to = elfmap_off + elfmap_size; assert (elfmap == elfmap_base || (elfmap_base - elfmap == (ptrdiff_t) ((min_len_bytes + ps - 1) & ~(ps - 1)))); @@ -675,8 +675,8 @@ read_block (int fd, const char *fname, off64_t fdlen, off64_t from, off64_t to) assert (handled_to % ps == 0); assert (handled_to % bytes_per_char == 0); - if (mmap64 (remap_base, read_now, PROT_READ, - MAP_PRIVATE | MAP_POPULATE | MAP_FIXED, fd, handled_to) + if (mmap (remap_base, read_now, PROT_READ, + MAP_PRIVATE | MAP_POPULATE | MAP_FIXED, fd, handled_to) == MAP_FAILED) error (EXIT_FAILURE, errno, gettext ("re-mmap failed")); elfmap_off = handled_to; @@ -700,14 +700,14 @@ read_block (int fd, const char *fname, off64_t fdlen, off64_t from, off64_t to) static int -read_fd (int fd, const char *fname, off64_t fdlen) +read_fd (int fd, const char *fname, off_t fdlen) { return read_block (fd, fname, fdlen, 0, fdlen); } static int -read_elf (Elf *elf, int fd, const char *fname, off64_t fdlen) +read_elf (Elf *elf, int fd, const char *fname, off_t fdlen) { assert (fdlen >= 0); diff --git a/src/strip.c b/src/strip.c index 6fdb3bf9..06d7cfd8 100644 --- a/src/strip.c +++ b/src/strip.c @@ -310,12 +310,12 @@ process_file (const char *fname) /* If we have to preserve the modify and access timestamps get them now. We cannot use fstat() after opening the file since the open would change the access time. */ - struct stat64 pre_st; + struct stat pre_st; struct timespec tv[2]; again: if (preserve_dates) { - if (stat64 (fname, &pre_st) != 0) + if (stat (fname, &pre_st) != 0) { error (0, errno, gettext ("cannot stat input file '%s'"), fname); return 1; @@ -338,8 +338,8 @@ process_file (const char *fname) /* We always use fstat() even if we called stat() before. This is done to make sure the information returned by stat() is for the same file. */ - struct stat64 st; - if (fstat64 (fd, &st) != 0) + struct stat st; + if (fstat (fd, &st) != 0) { error (0, errno, gettext ("cannot stat input file '%s'"), fname); return 1; @@ -2115,7 +2115,7 @@ while computing checksum for debug information")); || (pwrite_retry (fd, zero, sizeof zero, offsetof (Elf32_Ehdr, e_shentsize)) != sizeof zero) - || ftruncate64 (fd, shdr_info[shdridx].shdr.sh_offset) < 0) + || ftruncate (fd, shdr_info[shdridx].shdr.sh_offset) < 0) { error (0, errno, gettext ("while writing '%s'"), output_fname ?: fname); @@ -2135,7 +2135,7 @@ while computing checksum for debug information")); || (pwrite_retry (fd, zero, sizeof zero, offsetof (Elf64_Ehdr, e_shentsize)) != sizeof zero) - || ftruncate64 (fd, shdr_info[shdridx].shdr.sh_offset) < 0) + || ftruncate (fd, shdr_info[shdridx].shdr.sh_offset) < 0) { error (0, errno, gettext ("while writing '%s'"), output_fname ?: fname); diff --git a/src/unstrip.c b/src/unstrip.c index b725987c..bc8ed503 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -176,9 +176,9 @@ parse_opt (int key, char *arg, struct argp_state *state) if (info->output_dir != NULL) { - struct stat64 st; + struct stat st; error_t fail = 0; - if (stat64 (info->output_dir, &st) < 0) + if (stat (info->output_dir, &st) < 0) fail = errno; else if (!S_ISDIR (st.st_mode)) fail = ENOTDIR; @@ -1988,7 +1988,7 @@ DWARF data in '%s' not adjusted for prelinking bias; consider prelink -u"), make_directories (output_file); /* Copy the unstripped file and then modify it. */ - int outfd = open64 (output_file, O_RDWR | O_CREAT, + int outfd = open (output_file, O_RDWR | O_CREAT, stripped_ehdr->e_type == ET_REL ? 0666 : 0777); if (outfd < 0) error (EXIT_FAILURE, errno, _("cannot open '%s'"), output_file); @@ -2018,7 +2018,7 @@ DWARF data in '%s' not adjusted for prelinking bias; consider prelink -u"), static int open_file (const char *file, bool writable) { - int fd = open64 (file, writable ? O_RDWR : O_RDONLY); + int fd = open (file, writable ? O_RDWR : O_RDONLY); if (fd < 0) error (EXIT_FAILURE, errno, _("cannot open '%s'"), file); return fd; |