History

ftrace/trivial: Clean up recordmcount.c to use Linux style comparisons

The Linux ftrace subsystem style for comparing is: var == 1 var > 0 and not: 1 == var 0 < var It is considered that Linux developers are smart enough not to do the if (var = 1) mistake.

Steven Rostedt committed 15 years ago

Commit dd5477f1 parent 449a66f2 files · +32 −32Browse files

Unified · Split

2 files
  1. scripts/recordmcount.c +24 −24
  2. scripts/recordmcount.h +8 −8
scripts/recordmcount.c+24−24
@@ -78,7 +78,7 @@ static off_t · 77 unmodified lines
78ulseek(int const fd, off_t const offset, int const whence)78ulseek(int const fd, off_t const offset, int const whence)
79{79{
80 off_t const w = lseek(fd, offset, whence);80 off_t const w = lseek(fd, offset, whence);
81 if ((off_t)-1 == w) {81 if (w == (off_t)-1) {
82 perror("lseek");82 perror("lseek");
83 fail_file();83 fail_file();
84 }84 }
@@ -111,7 +111,7 @@ static void * · 26 unmodified lines
111umalloc(size_t size)111umalloc(size_t size)
112{112{
113 void *const addr = malloc(size);113 void *const addr = malloc(size);
114 if (0 == addr) {114 if (addr == 0) {
115 fprintf(stderr, "malloc failed: %zu bytes\n", size);115 fprintf(stderr, "malloc failed: %zu bytes\n", size);
116 fail_file();116 fail_file();
117 }117 }
@@ -136,7 +136,7 @@ static void *mmap_file(char const *fname) · 18 unmodified lines
136 void *addr;136 void *addr;
137 137
138 fd_map = open(fname, O_RDWR);138 fd_map = open(fname, O_RDWR);
139 if (0 > fd_map || 0 > fstat(fd_map, &sb)) {139 if (fd_map < 0 || fstat(fd_map, &sb) < 0) {
140 perror(fname);140 perror(fname);
141 fail_file();141 fail_file();
142 }142 }
@@ -147,7 +147,7 @@ static void *mmap_file(char const *fname) · 4 unmodified lines
147 addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE,147 addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE,
148 fd_map, 0);148 fd_map, 0);
149 mmap_failed = 0;149 mmap_failed = 0;
150 if (MAP_FAILED == addr) {150 if (addr == MAP_FAILED) {
151 mmap_failed = 1;151 mmap_failed = 1;
152 addr = umalloc(sb.st_size);152 addr = umalloc(sb.st_size);
153 uread(fd_map, addr, sb.st_size);153 uread(fd_map, addr, sb.st_size);
@@ -206,12 +206,12 @@ static uint32_t (*w2)(uint16_t); · 52 unmodified lines
206static int206static int
207is_mcounted_section_name(char const *const txtname)207is_mcounted_section_name(char const *const txtname)
208{208{
209 return 0 == strcmp(".text", txtname) ||209 return strcmp(".text", txtname) == 0 ||
210 0 == strcmp(".ref.text", txtname) ||210 strcmp(".ref.text", txtname) == 0 ||
211 0 == strcmp(".sched.text", txtname) ||211 strcmp(".sched.text", txtname) == 0 ||
212 0 == strcmp(".spinlock.text", txtname) ||212 strcmp(".spinlock.text", txtname) == 0 ||
213 0 == strcmp(".irqentry.text", txtname) ||213 strcmp(".irqentry.text", txtname) == 0 ||
214 0 == strcmp(".text.unlikely", txtname);214 strcmp(".text.unlikely", txtname) == 0;
215}215}
216 216
217/* 32 bit and 64 bit are very similar */217/* 32 bit and 64 bit are very similar */
@@ -270,7 +270,7 @@ do_file(char const *const fname) · 52 unmodified lines
270 fail_file();270 fail_file();
271 } break;271 } break;
272 case ELFDATA2LSB: {272 case ELFDATA2LSB: {
273 if (1 != *(unsigned char const *)&endian) {273 if (*(unsigned char const *)&endian != 1) {
274 /* main() is big endian, file.o is little endian. */274 /* main() is big endian, file.o is little endian. */
275 w = w4rev;275 w = w4rev;
276 w2 = w2rev;276 w2 = w2rev;
@@ -278,7 +278,7 @@ do_file(char const *const fname) · 1 unmodified line
278 }278 }
279 } break;279 } break;
280 case ELFDATA2MSB: {280 case ELFDATA2MSB: {
281 if (0 != *(unsigned char const *)&endian) {281 if (*(unsigned char const *)&endian != 0) {
282 /* main() is little endian, file.o is big endian. */282 /* main() is little endian, file.o is big endian. */
283 w = w4rev;283 w = w4rev;
284 w2 = w2rev;284 w2 = w2rev;
@@ -286,9 +286,9 @@ do_file(char const *const fname) · 1 unmodified line
286 }286 }
287 } break;287 } break;
288 } /* end switch */288 } /* end switch */
289 if (0 != memcmp(ELFMAG, ehdr->e_ident, SELFMAG)289 if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0
290 || ET_REL != w2(ehdr->e_type)290 || w2(ehdr->e_type) != ET_REL
291 || EV_CURRENT != ehdr->e_ident[EI_VERSION]) {291 || ehdr->e_ident[EI_VERSION] != EV_CURRENT) {
292 fprintf(stderr, "unrecognized ET_REL file %s\n", fname);292 fprintf(stderr, "unrecognized ET_REL file %s\n", fname);
293 fail_file();293 fail_file();
294 }294 }
@@ -321,15 +321,15 @@ do_file(char const *const fname) · 26 unmodified lines
321 fail_file();321 fail_file();
322 } break;322 } break;
323 case ELFCLASS32: {323 case ELFCLASS32: {
324 if (sizeof(Elf32_Ehdr) != w2(ehdr->e_ehsize)324 if (w2(ehdr->e_ehsize) != sizeof(Elf32_Ehdr)
325 || sizeof(Elf32_Shdr) != w2(ehdr->e_shentsize)) {325 || w2(ehdr->e_shentsize) != sizeof(Elf32_Shdr)) {
326 fprintf(stderr,326 fprintf(stderr,
327 "unrecognized ET_REL file: %s\n", fname);327 "unrecognized ET_REL file: %s\n", fname);
328 fail_file();328 fail_file();
329 }329 }
330 if (EM_S390 == w2(ehdr->e_machine))330 if (w2(ehdr->e_machine) == EM_S390)
331 reltype = R_390_32;331 reltype = R_390_32;
332 if (EM_MIPS == w2(ehdr->e_machine)) {332 if (w2(ehdr->e_machine) == EM_MIPS) {
333 reltype = R_MIPS_32;333 reltype = R_MIPS_32;
334 is_fake_mcount32 = MIPS32_is_fake_mcount;334 is_fake_mcount32 = MIPS32_is_fake_mcount;
335 }335 }
@@ -337,15 +337,15 @@ do_file(char const *const fname) · 1 unmodified line
337 } break;337 } break;
338 case ELFCLASS64: {338 case ELFCLASS64: {
339 Elf64_Ehdr *const ghdr = (Elf64_Ehdr *)ehdr;339 Elf64_Ehdr *const ghdr = (Elf64_Ehdr *)ehdr;
340 if (sizeof(Elf64_Ehdr) != w2(ghdr->e_ehsize)340 if (w2(ghdr->e_ehsize) != sizeof(Elf64_Ehdr)
341 || sizeof(Elf64_Shdr) != w2(ghdr->e_shentsize)) {341 || w2(ghdr->e_shentsize) != sizeof(Elf64_Shdr)) {
342 fprintf(stderr,342 fprintf(stderr,
343 "unrecognized ET_REL file: %s\n", fname);343 "unrecognized ET_REL file: %s\n", fname);
344 fail_file();344 fail_file();
345 }345 }
346 if (EM_S390 == w2(ghdr->e_machine))346 if (w2(ghdr->e_machine) == EM_S390)
347 reltype = R_390_64;347 reltype = R_390_64;
348 if (EM_MIPS == w2(ghdr->e_machine)) {348 if (w2(ghdr->e_machine) == EM_MIPS) {
349 reltype = R_MIPS_64;349 reltype = R_MIPS_64;
350 Elf64_r_sym = MIPS64_r_sym;350 Elf64_r_sym = MIPS64_r_sym;
351 Elf64_r_info = MIPS64_r_info;351 Elf64_r_info = MIPS64_r_info;
@@ -371,7 +371,7 @@ main(int argc, char const *argv[]) · 19 unmodified lines
371 }371 }
372 372
373 /* Process each file in turn, allowing deep failure. */373 /* Process each file in turn, allowing deep failure. */
374 for (--argc, ++argv; 0 < argc; --argc, ++argv) {374 for (--argc, ++argv; argc > 0; --argc, ++argv) {
375 int const sjval = setjmp(jmpenv);375 int const sjval = setjmp(jmpenv);
376 int len;376 int len;
377 377
scripts/recordmcount.h+8−8
@@ -275,12 +275,12 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, · 274 unmodified lines
275 Elf_Sym const *const symp =275 Elf_Sym const *const symp =
276 &sym0[Elf_r_sym(relp)];276 &sym0[Elf_r_sym(relp)];
277 char const *symname = &str0[w(symp->st_name)];277 char const *symname = &str0[w(symp->st_name)];
278 char const *mcount = '_' == gpfx ? "_mcount" : "mcount";278 char const *mcount = gpfx == '_' ? "_mcount" : "mcount";
279 279
280 if ('.' == symname[0])280 if (symname[0] == '.')
281 ++symname; /* ppc64 hack */281 ++symname; /* ppc64 hack */
282 if (0 == strcmp(mcount, symname) ||282 if (strcmp(mcount, symname) == 0 ||
283 (altmcount && 0 == strcmp(altmcount, symname)))283 (altmcount && strcmp(altmcount, symname) == 0))
284 mcountsym = Elf_r_sym(relp);284 mcountsym = Elf_r_sym(relp);
285 }285 }
286 286
@@ -290,7 +290,7 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, · 3 unmodified lines
290 mrelp->r_offset = _w(offbase290 mrelp->r_offset = _w(offbase
291 + ((void *)mlocp - (void *)mloc0));291 + ((void *)mlocp - (void *)mloc0));
292 Elf_r_info(mrelp, recsym, reltype);292 Elf_r_info(mrelp, recsym, reltype);
293 if (sizeof(Elf_Rela) == rel_entsize) {293 if (rel_entsize == sizeof(Elf_Rela)) {
294 ((Elf_Rela *)mrelp)->r_addend = addend;294 ((Elf_Rela *)mrelp)->r_addend = addend;
295 *mlocp++ = 0;295 *mlocp++ = 0;
296 } else296 } else
@@ -354,12 +354,12 @@ __has_rel_mcount(Elf_Shdr const *const relhdr, /* is SHT_REL or SHT_RELA */ · 57 unmodified lines
354 Elf_Shdr const *const txthdr = &shdr0[w(relhdr->sh_info)];354 Elf_Shdr const *const txthdr = &shdr0[w(relhdr->sh_info)];
355 char const *const txtname = &shstrtab[w(txthdr->sh_name)];355 char const *const txtname = &shstrtab[w(txthdr->sh_name)];
356 356
357 if (0 == strcmp("__mcount_loc", txtname)) {357 if (strcmp("__mcount_loc", txtname) == 0) {
358 fprintf(stderr, "warning: __mcount_loc already exists: %s\n",358 fprintf(stderr, "warning: __mcount_loc already exists: %s\n",
359 fname);359 fname);
360 succeed_file();360 succeed_file();
361 }361 }
362 if (SHT_PROGBITS != w(txthdr->sh_type) ||362 if (w(txthdr->sh_type) != SHT_PROGBITS ||
363 !is_mcounted_section_name(txtname))363 !is_mcounted_section_name(txtname))
364 return NULL;364 return NULL;
365 return txtname;365 return txtname;
@@ -370,7 +370,7 @@ static char const *has_rel_mcount(Elf_Shdr const *const relhdr, · 4 unmodified lines
370 char const *const shstrtab,370 char const *const shstrtab,
371 char const *const fname)371 char const *const fname)
372{372{
373 if (SHT_REL != w(relhdr->sh_type) && SHT_RELA != w(relhdr->sh_type))373 if (w(relhdr->sh_type) != SHT_REL && w(relhdr->sh_type) != SHT_RELA)
374 return NULL;374 return NULL;
375 return __has_rel_mcount(relhdr, shdr0, shstrtab, fname);375 return __has_rel_mcount(relhdr, shdr0, shstrtab, fname);
376}376}