Verify that source and object codes are compatible

Asked 5 months ago, Updated 5 months ago, 10 views

c Is there a way to verify that the object code compiled by the compiler corresponds to the source code?

Thank you for all your answers.The environment is iOS development on a Mac.


2022-09-30 13:53

5 Answers

For older source management systems such as RCS or CVS, if you write keywords such as $Id$ in the source code, you commit them.

$Id:samp.c, v1.5 1993/10/19 14:57:32 ceder Exp$

It can be replaced by a string such as .Use this to enter the source code

const charge[]="$Id:samp.c, v1.5 1993/10/19 14:57:32 ceder Exp$";

The same string will automatically be embedded in the object code.There was a time when this method was used to verify the correspondence between source and object codes.

Visual Studio maintains a checksum of the source code in the debug information in the object file, so the debugger and others are checking that the object code, debug information, and source code match.You can also see this by selecting a hash algorithm in the compilation option/ZH.

2022-09-30 13:53

Short Answer:Define "matching" before you begin.

Long answer: This depends on the requirements or requirements.First of all, suppose you have the same development environment (same compiler, same header) as when you created the original object file, and the compilation option is known by Makefile (because it is impossible without it)

If you compile the source code with the same compiler header compilation option as before, I think you can normally create exactly the same object file.In fact, there are environments in which the same object file is generated by comparing the contents of the object file, exceptions include:

Therefore, physical matching of bytes in an object file can be incorrect.Therefore, you must define what matches and how they should match.

It's a good idea that the reverse assembly matches, but it might be slightly redundant.
make compare in has previously examined the matchability comparison of stageN objects.In our hppa 2.0w-hp-hpux 11.11, the contents of the file are skipped with cmp --ignore-initial=16.
Visual C++ will embed the compile time stamp (2.) and should be excluded.

You must gather information before deciding the specifications.

2022-09-30 13:53

If you have the same compilation environment that compiled the object, you may want to recompile it and look at the diff of the object.If compiled in the same source code environment, the contents of the file will match exactly.

2022-09-30 13:53

It seems difficult to judge unless the conditions are met.

You can also use cmp to compare object files.

cmp-s Comparison Contrast Object File Compiled for Comparison

b When executed with bash

You must use the same compilation options for comparison.
< If the options such as -O and -g change, the contents of the object file are likely to change.

You must use the same compiler.
Object files generated by gcc and clang were different sizes.

Commands Used for Research
clang version 9.0.0 (trunk362692) (llvm/trunk362690)
gcc(Ubuntu 7.4.0-1 ubuntu 1 to 18.04.1) 7.4.0
cmp (GNU diffutils) 3.6

2022-09-30 13:53

I'm a questioner. I'd like to disassemble it for your reference.

2022-09-30 13:53

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.