Skip to content

Commit c81a6a6

Browse files
authored
Merge pull request #7932 from tautschnig/cleanup/asm-library
C library: ASM functions take void* pointers
2 parents 718587a + 0fff131 commit c81a6a6

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

Diff for: .github/workflows/build-and-test-Xen.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ jobs:
6262

6363
- name: Check for goto-cc section in xen-syms binary
6464
run: objdump -h xen_4_13/xen/xen-syms | grep "goto-cc"
65+
66+
- name: Show goto-cc properties
67+
run: $(pwd)/src/cbmc/cbmc --show-properties xen_4_13/xen/xen-syms
68+
69+
- name: Show some goto-cc functions
70+
run: $(pwd)/src/cbmc/cbmc --list-goto-functions xen_4_13/xen/xen-syms | grep "arch"

Diff for: src/ansi-c/library/x86_assembler.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33

44
extern int __CPROVER_rounding_mode;
55

6-
void __asm_fnstcw(unsigned short *dest)
6+
void __asm_fnstcw(void *dest)
77
{
88
// the rounding mode is bits 10 and 11 in the control word
9-
*dest=__CPROVER_rounding_mode<<10;
9+
*(unsigned short *)dest = __CPROVER_rounding_mode << 10;
1010
}
1111

1212
/* FUNCTION: __asm_fstcw */
1313

1414
extern int __CPROVER_rounding_mode;
1515

16-
void __asm_fstcw(unsigned short *dest)
16+
void __asm_fstcw(void *dest)
1717
{
1818
// the rounding mode is bits 10 and 11 in the control word
19-
*dest=__CPROVER_rounding_mode<<10;
19+
*(unsigned short *)dest = __CPROVER_rounding_mode << 10;
2020
}
2121

2222
/* FUNCTION: __asm_fldcw */
2323

2424
extern int __CPROVER_rounding_mode;
2525

26-
void __asm_fldcw(const unsigned short *src)
26+
void __asm_fldcw(void *src)
2727
{
2828
// the rounding mode is bits 10 and 11 in the control word
29-
__CPROVER_rounding_mode=((*src)>>10)&3;
29+
__CPROVER_rounding_mode = ((*(const unsigned short *)src) >> 10) & 3;
3030
}
3131

3232
/* FUNCTION: __asm_mfence */

Diff for: src/assembler/remove_asm.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class remove_asmt
6868
void gcc_asm_function_call(
6969
const irep_idt &function_base_name,
7070
const code_asm_gcct &code,
71+
std::size_t n_args,
7172
goto_programt &dest);
7273

7374
void msc_asm_function_call(
@@ -83,10 +84,12 @@ class remove_asmt
8384
/// \param function_base_name: Name of the function to call
8485
/// \param code: gcc-style inline assembly statement to translate to function
8586
/// call
87+
/// \param n_args: Number of arguments required by \p function_base_name
8688
/// \param dest: Goto program to append the function call to
8789
void remove_asmt::gcc_asm_function_call(
8890
const irep_idt &function_base_name,
8991
const code_asm_gcct &code,
92+
std::size_t n_args,
9093
goto_programt &dest)
9194
{
9295
irep_idt function_identifier = function_base_name;
@@ -115,6 +118,16 @@ void remove_asmt::gcc_asm_function_call(
115118
}
116119
}
117120

121+
// An inline asm statement may consist of multiple commands, not all of which
122+
// use all of the inputs/outputs of the inline asm statement.
123+
DATA_INVARIANT_WITH_DIAGNOSTICS(
124+
arguments.size() >= n_args,
125+
"insufficient number of arguments for calling " +
126+
id2string(function_identifier),
127+
"required arguments: " + std::to_string(n_args),
128+
code.pretty());
129+
arguments.resize(n_args);
130+
118131
code_typet fkt_type{
119132
code_typet::parameterst{
120133
arguments.size(), code_typet::parametert{void_pointer}},
@@ -139,9 +152,12 @@ void remove_asmt::gcc_asm_function_call(
139152
}
140153
else
141154
{
142-
DATA_INVARIANT(
155+
DATA_INVARIANT_WITH_DIAGNOSTICS(
143156
symbol_table.lookup_ref(function_identifier).type == fkt_type,
144-
"function types should match");
157+
"types of function " + id2string(function_identifier) + " should match",
158+
code.pretty(),
159+
symbol_table.lookup_ref(function_identifier).type.pretty(),
160+
fkt_type.pretty());
145161
}
146162
}
147163

@@ -299,12 +315,12 @@ void remove_asmt::process_instruction_gcc(
299315

300316
if(command == "fstcw" || command == "fnstcw" || command == "fldcw") // x86
301317
{
302-
gcc_asm_function_call("__asm_" + id2string(command), code, tmp_dest);
318+
gcc_asm_function_call("__asm_" + id2string(command), code, 1, tmp_dest);
303319
}
304320
else if(
305321
command == "mfence" || command == "lfence" || command == "sfence") // x86
306322
{
307-
gcc_asm_function_call("__asm_" + id2string(command), code, tmp_dest);
323+
gcc_asm_function_call("__asm_" + id2string(command), code, 0, tmp_dest);
308324
}
309325
else if(command == ID_sync) // Power
310326
{

0 commit comments

Comments
 (0)